android - RecyclerView onScrolled not called when use scrollToPosition -
i have recyclerview.onscrolllistener
this
findviewbyid(r.id.button_scroll_to_position).setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { mlinearlayoutmanager.scrolltopositionwithoffset(2,0); } }); mrecyclerview.addonscrolllistener(new recyclerview.onscrolllistener() { @override public void onscrolled(recyclerview recyclerview, int dx, int dy) { super.onscrolled(recyclerview, dx, dy); log.i("tag", "scroll " + dy); } }); arraylist<string> list = new arraylist<>(); (int = 0; < 7; i++) { list.add("" + i); } mrecyclerview.setadapter(new simplervadapter(list)); mlinearlayoutmanager.scrolltopositionwithoffset(2,0);
however in case onscrolled
don't call event recyclerview
have scrolled (using scrolltopositionwithoffset
).
know reason when use scrolltopositionwithoffset
(or scrolltoposition
) onscrolled
call when firstvisibleitem
, lastvisibleitem
change. can see in demo (if firstvisibleitem=2 , lastvisibleitem=5 => onscrolled not called, firstvisibleitem=2 , lastvisibleitem=6 => onscrolled called)
is there trick or workaround way receive onscrolled
when use scrolltoposition
?
any or suggestion great appreciated.
i found in case recyclerview
scrolled, firstvisibleitem
, lastvisibleitem
not change then recyclerview.onscrolllistener
not called view.onlayoutchangelistener called
therefore, use both onscrolllistener
, onlayoutchangelistener
listen recyclerview
scroll.
i'm still looking better solution
Comments
Post a Comment