How can i control the scrolling speed of recyclerView.smoothScrollToPosition(position)

前端 未结 5 609
感情败类
感情败类 2020-11-28 23:18

I have a recycler view... and i want a smooth scrolldown and then scrollup to it programatically to show the complete content in it to user .... And i m able to do this by<

5条回答
  •  抹茶落季
    2020-11-29 00:01

    For those uninterested in overriding LinearLayoutManager (or whichever subclass you're using), you can just call startSmoothScroll(smoothScroller) directly on the layout manager.

    LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {
    
        @Override
        protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
            return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
        }
    };
    
    linearSmoothScroller.setTargetPosition(position);
    layoutManager.startSmoothScroll(linearSmoothScroller);
    

提交回复
热议问题