Smooth scroll recyclerview android -
i have recyclerview
contains ratingbar
in list_items.xml
on completion of rating of 1 item in recyclerview
scroll item of recyclerview
automatically
the scrolling fast , user couldn't know scrolled.
i implemented smooth scroll , not working properly, first scroll of 2nd item smooth (1st displayed ), other items scroll fast
linearlayoutsmoothscroll.java
public class linearlayoutsmoothscroll extends linearlayoutmanager { private static final float milliseconds_per_inch = 100f; private context mcontext; public linearlayoutsmoothscroll(context context) { super(context); mcontext=context; } public linearlayoutsmoothscroll(context context, int orientation, boolean reverselayout) { super(context, orientation, reverselayout); mcontext=context; } public linearlayoutsmoothscroll(context context, attributeset attrs, int defstyleattr, int defstyleres) { super(context, attrs, defstyleattr, defstyleres); mcontext=context; } @override public void smoothscrolltoposition(recyclerview recyclerview, recyclerview.state state, final int position) { linearsmoothscroller smoothscroller = new linearsmoothscroller(mcontext) { //this controls direction in smoothscroll looks //for view @override public pointf computescrollvectorforposition (int targetposition) { return linearlayoutsmoothscroll.this .computescrollvectorforposition(targetposition); } //this returns milliseconds takes //scroll 1 pixel. @override protected float calculatespeedperpixel (displaymetrics displaymetrics) { return milliseconds_per_inch/displaymetrics.densitydpi; } }; smoothscroller.settargetposition(position); startsmoothscroll(smoothscroller); } }
usage :
layoutmanager.smoothscrolltoposition(rvsurvey,new recyclerview.state(),new_position);
Comments
Post a Comment