android - RecyclerView smoothScroolToPositionFromTop() -
is there alternatives listview's smoothscrolltopositionfromtop() recyclerview? trying migrate listview code recyclerview, , don't see recyclerview version of anywhere.
there 1 method called recyclerview.smoothscrolltoposition() , cannot define offset relative top element of screen (i need list scroll position, , stop when position first visible child in list).
to smooth scroll target position top can use custom linearlayoutmanager that:
public class customlinearlayoutmanager extends linearlayoutmanager { private context context; public customlinearlayoutmanager(context context) { super(context); this.context = context; } public customlinearlayoutmanager(context context, int orientation, boolean reverselayout) { super(context, orientation, reverselayout); this.context = context; } public customlinearlayoutmanager(context context, attributeset attrs, int defstyleattr, int defstyleres) { super(context, attrs, defstyleattr, defstyleres); this.context = context; } @override public void smoothscrolltoposition(recyclerview recyclerview, recyclerview.state state, int position) { linearsmoothscroller smoothscroller = new linearsmoothscroller(context) { @override public pointf computescrollvectorforposition(int targetposition) { return customlinearlayoutmanager.this.computescrollvectorforposition(targetposition); } @override protected int getverticalsnappreference() { return snap_to_start; } }; smoothscroller.settargetposition(position); startsmoothscroll(smoothscroller); } }
Comments
Post a Comment