/**滚动页面 * @param upToDown */ private void scrollPage(boolean upToDown) { Log.d(TAG, "scrollPage upToDown = " + upToDown + "; lv.getHeight() = " + lv.getHeight()); lv.smoothScrollBy((int) ((upToDown ? -0.8 : 0.8) * lv.getHeight()), 120); }
public static void scrollListBy(@NonNull AbsListView listView, int y) { if (Build.VERSION.SDK_INT >= 19) { // Call the framework version directly listView.scrollListBy(y); } else if (listView instanceof ListView) { // provide backport on earlier versions final int firstPosition = listView.getFirstVisiblePosition(); if (firstPosition == ListView.INVALID_POSITION) { return; } //noinspection UnnecessaryLocalVariable final ViewGroup listGroup = listView; final View firstView = listGroup.getChildAt(0); if (firstView == null) { return; } final int newTop = firstView.getTop() - y; ((ListView) listView).setSelectionFromTop(firstPosition, newTop); } else { listView.smoothScrollBy(y, 0); } }
private void scrollback(int offset) { View child = mContentView.getContentView(); if (child instanceof AbsListView) { AbsListView absListView = (AbsListView) child; absListView.smoothScrollBy(offset, 0); } }
@Override public void scrollAViewBy(int dp) { absListView.smoothScrollBy(dp, 0); } }
@Override public void run() { absListView.smoothScrollBy(250, 250); } }, 250); // give time for EXIF data to appear
@Override public void smoothScrollBy(final int distance, final int duration) { mAbsListView.smoothScrollBy(distance, duration); }
public static void scrollAViewBy(View view, int height) { if (view instanceof RecyclerView) ((RecyclerView) view).scrollBy(0, height); else if (view instanceof ScrollView) ((ScrollView) view).smoothScrollBy(0, height); else if (view instanceof AbsListView) ((AbsListView) view).smoothScrollBy(height, 0); else { try { Method method = view.getClass().getDeclaredMethod("smoothScrollBy", Integer.class, Integer.class); method.invoke(view, 0, height); } catch (Exception e) { view.scrollBy(0, height); } } }
private static void scrollToPrevious(AbsListView absListView) { if (absListView == null) return; int height = absListView.getHeight() - PAGE_SCROLL_OFFSET_PX; if (height <= 0) height = absListView.getHeight(); absListView.smoothScrollBy(-1 * height, PAGE_SCROLL_DURATION_MS); }
private static void scrollToNext(AbsListView absListView) { if (absListView == null) return; int height = absListView.getHeight() - PAGE_SCROLL_OFFSET_PX; if (height <= 0) height = absListView.getHeight(); absListView.smoothScrollBy(height, PAGE_SCROLL_DURATION_MS); } }
@SuppressLint("NewApi") public void smoothScrollBy(int velocityY, int distance, int duration) { View scrollableView = getScrollableView(); if (scrollableView instanceof AbsListView) { AbsListView absListView = (AbsListView) scrollableView; if (sysVersion >= 21) { absListView.fling(velocityY); } else { absListView.smoothScrollBy(distance, duration); } } else if (scrollableView instanceof ScrollView) { ((ScrollView) scrollableView).fling(velocityY); } else if (scrollableView instanceof RecyclerView) { ((RecyclerView) scrollableView).fling(0, velocityY); } else if (scrollableView instanceof WebView) { ((WebView)scrollableView).flingScroll(0,velocityY); } } }
/** * 将特定的view按照初始条件滚动 * * @param velocityY 初始滚动速度 * @param distance 需要滚动的距离 * @param duration 允许滚动的时间 */ @SuppressLint("NewApi") public void smoothScrollBy(int velocityY, int distance, int duration) { View scrollableView = getScrollableView(); if (scrollableView instanceof AbsListView) { AbsListView absListView = (AbsListView) scrollableView; if (sysVersion >= 21) { absListView.fling(velocityY); } else { absListView.smoothScrollBy(distance, duration); } } else if (scrollableView instanceof ScrollView) { ((ScrollView) scrollableView).fling(velocityY); } else if (scrollableView instanceof RecyclerView) { ((RecyclerView) scrollableView).fling(0, velocityY); } else if (scrollableView instanceof WebView) { ((WebView) scrollableView).flingScroll(0, velocityY); } } }
/** * 将特定的view按照初始条件滚动 * * @param velocityY 初始滚动速度 * @param distance 需要滚动的距离 * @param duration 允许滚动的时间 */ @SuppressLint("NewApi") public void smoothScrollBy(int velocityY, int distance, int duration) { View scrollableView = getScrollableView(); if (scrollableView instanceof AbsListView) { AbsListView absListView = (AbsListView) scrollableView; if (sysVersion >= 21) { absListView.fling(velocityY); } else { absListView.smoothScrollBy(distance, duration); } } else if (scrollableView instanceof ScrollView) { ((ScrollView) scrollableView).fling(velocityY); } else if (scrollableView instanceof RecyclerView) { ((RecyclerView) scrollableView).fling(0, velocityY); } else if (scrollableView instanceof WebView) { ((WebView) scrollableView).flingScroll(0, velocityY); } } }
final int extraScroll = lastPos < mList.getCount() - 1 ? mExtraScroll : mList.getPaddingBottom(); mList.smoothScrollBy(lastViewHeight - lastViewPixelsShowing + extraScroll, mScrollDuration); final int extraScroll = firstPos > 0 ? mExtraScroll : mList.getPaddingTop(); mList.smoothScrollBy(firstViewTop - extraScroll, mScrollDuration);
((AbsListView) getListViewWrapper().getListView()).smoothScrollBy(scrollDistance, (int) (mScrolldownAnimationDurationMs * numInsertedAbove));