@UiThread public void scrollSmoothToPosition( int position, final int offset, final SmoothScrollAlignmentType type) { if (mMountedView == null) { mCurrentFirstVisiblePosition = position; mCurrentOffset = offset; mSmoothScrollAlignmentType = type; return; } final int target = type == SmoothScrollAlignmentType.SNAP_TO_CENTER ? position + 1 : position; final RecyclerView.SmoothScroller smoothScroller = SnapUtil.getSmoothScrollerWithOffset(mComponentContext.getAndroidContext(), offset, type); smoothScroller.setTargetPosition(target); mMountedView.getLayoutManager().startSmoothScroll(smoothScroller); }
layoutManager.startSmoothScroll(smoothScroller);
/** * Helper method to facilitate for snapping triggered by a fling. * * @param layoutManager The {@link RecyclerView.LayoutManager} associated with the attached * {@link RecyclerView}. * @param velocityX Fling velocity on the horizontal axis. * @param velocityY Fling velocity on the vertical axis. * @return true if it is handled, false otherwise. */ private boolean snapFromFling(@NonNull RecyclerView.LayoutManager layoutManager, int velocityX, int velocityY) { if (!(layoutManager instanceof RecyclerView.SmoothScroller.ScrollVectorProvider)) { return false; } RecyclerView.SmoothScroller smoothScroller = createSnapScroller(layoutManager); if (smoothScroller == null) { return false; } int targetPosition = findTargetSnapPosition(layoutManager, velocityX, velocityY); if (targetPosition == RecyclerView.NO_POSITION) { return false; } smoothScroller.setTargetPosition(targetPosition); layoutManager.startSmoothScroll(smoothScroller); return true; }
return; getLayoutManager().startSmoothScroll(linearSmoothScroller); } else { super.smoothScrollToPosition(position);
return; getLayoutManager().startSmoothScroll(scroller); } else { super.smoothScrollToPosition(position);
public void startSmoothScroll(RecyclerView.SmoothScroller smoothScroller) { layoutManager.startSmoothScroll(smoothScroller); }