android - Scroll multiple recyclerviews on one recyclerview scroll -
i have arraylist
of recyclerveiws
in recyclerview
, want know how scroll of them when 1 scrolled.
have far, gives me stack overflow error:
holder.rv.setonscrolllistener(new recyclerview.onscrolllistener() { @override public void onscrollstatechanged(recyclerview recyclerview, int newstate) { super.onscrollstatechanged(recyclerview, newstate); } @override public void onscrolled(recyclerview recyclerview, int dx, int dy) { super.onscrolled(recyclerview, dx, dy); if (dx != -199382734) (sched_vh vh : vhs) { if (vh != holder) vh.rv.scrollby(-199382734, dy); } } });
i have worked on problem friend few hours..the final answer simple. main idea 2 recyclerviews should use same onscrolllistener instead of different ones, listener recyclerview scrolling, , avoid stack on flow. please try following
//rcv , leftrcv 2 recyclerviews recyclerview.onscrolllistener scrolllistener = new recyclerview.onscrolllistener() { @override public void onscrolled(recyclerview recyclerview, int dx, int dy) { if (recyclerview == leftrcv) { rcv.removeonscrolllistener(this); rcv.scrollby(0, dy); rcv.addonscrolllistener(this); } else if (recyclerview == rcv) { leftrcv.removeonscrolllistener(this); leftrcv.scrollby(0, dy); leftrcv.addonscrolllistener(this); } } @override public void onscrollstatechanged(recyclerview recyclerview, int newstate) { super.onscrollstatechanged(recyclerview, newstate); } }; leftrcv.addonscrolllistener(scrolllistener); rcv.addonscrolllistener(scrolllistener);
but don't know whether result in performance issue...