Android : Control Smooth scroll over recycler view

后端 未结 3 917
慢半拍i
慢半拍i 2020-12-02 04:42

I am using Recyclerview with CardView. I am aware how to control speed on list view. But not for Recyclerview.

I searched a lot in found class name SmoothScroll. How

3条回答
  •  死守一世寂寞
    2020-12-02 05:40

    Simply implement smoothScrollToPosition() of your LinearLayoutManager:

    LinearLayoutManager layoutManager = new LinearLayoutManager(this) {
    
        @Override
        public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
            LinearSmoothScroller smoothScroller = new LinearSmoothScroller(this) {
    
                private static final float SPEED = 300f;// Change this value (default=25f)
    
                @Override
                protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
                    return SPEED / displayMetrics.densityDpi;
                }
    
            };
            smoothScroller.setTargetPosition(position);
            startSmoothScroll(smoothScroller);
        }
    
    };
    

提交回复
热议问题