Java Code Examples for androidx.recyclerview.widget.LinearSmoothScroller#setTargetPosition()

The following examples show how to use androidx.recyclerview.widget.LinearSmoothScroller#setTargetPosition() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SmoothScrollingLinearLayoutManager.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
public void smoothScrollToPosition(@NonNull Context context, int position, float millisecondsPerInch) {
  final LinearSmoothScroller scroller = new LinearSmoothScroller(context) {
    @Override
    protected int getVerticalSnapPreference() {
      return LinearSmoothScroller.SNAP_TO_END;
    }

    @Override
    protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
      return millisecondsPerInch / displayMetrics.densityDpi;
    }
  };

  scroller.setTargetPosition(position);
  startSmoothScroll(scroller);
}
 
Example 2
Source File: HierarchyFragment.java    From pandora with Apache License 2.0 6 votes vote down vote up
@Override
protected RecyclerView.LayoutManager onCreateLayoutManager() {
    return new LinearLayoutManager(Utils.getContext()) {
        @Override
        public void smoothScrollToPosition(RecyclerView recyclerView,
                                           RecyclerView.State state, final int position) {
            LinearSmoothScroller smoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {
                @Override
                protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
                    // let scroll smooth more
                    return 120f / displayMetrics.densityDpi;
                }

                @Override
                protected int getVerticalSnapPreference() {
                    return SNAP_TO_START;
                }
            };
            smoothScroller.setTargetPosition(position);
            startSmoothScroll(smoothScroller);
        }
    };
}
 
Example 3
Source File: SmoothCalendarLayoutManager.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Override
public void smoothScrollToPosition(
    RecyclerView recyclerView, RecyclerView.State state, int position) {
  final LinearSmoothScroller linearSmoothScroller =
      new LinearSmoothScroller(recyclerView.getContext()) {

        @Override
        protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
          return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
        }
      };
  linearSmoothScroller.setTargetPosition(position);
  startSmoothScroll(linearSmoothScroller);
}
 
Example 4
Source File: ViewPagerLayoutManager.java    From OmegaRecyclerView with MIT License 4 votes vote down vote up
private void startSmoothPendingScroll() {
    LinearSmoothScroller scroller = new DiscreteLinearSmoothScroller(mContext);
    scroller.setTargetPosition(calculateRealPosition(mCurrentPosition));
    startSmoothScroll(scroller);
}