I want to scroll multiple RecyclerView
at a time how to achieve that Exp- I have 3 RecyclerView
in horizontal and when i scroll 1st RecyclerView
then second and third shoul also scroll how to do that ?

- 1,373
- 3
- 15
- 34

- 21
- 5
-
you should post some code – Ajit Pratap Singh Oct 13 '16 at 04:44
-
http://android-pratap.blogspot.in/2015/12/horizontal-recyclerview-in-vertical.html – Akshaya Dikshit Oct 13 '16 at 05:08
-
this is code where horizontal multiple scrollview are there i want to scroll all at a time of scrolling one – Akshaya Dikshit Oct 13 '16 at 05:08
-
Why are you creating 3 RecyclerViews? Why not just use one `StaggeredRecyclerViewAdapter` with `StaggeredGridLayoutManager`, it allows you to set the number of columns you need. Here is a good example: https://www.youtube.com/watch?v=Lq3Wvcy1kHo https://github.com/mitchtabian/Recyclerview/tree/master/RecyclerViewStaggered – Waqleh Feb 04 '20 at 12:44
-
Does this answer your question? [Sync scrolling of multiple RecyclerViews](https://stackoverflow.com/questions/30702726/sync-scrolling-of-multiple-recyclerviews) – Waqleh Feb 04 '20 at 12:45
1 Answers
The answer is very simple, you have to get scroll feedback from one recycleview and pass it to other recycleviews. But very carefully.
you need to keep referance of which recyclerview starts giving scroll feedback, so that it won't enter into continious loop.
so create a global variable
private int draggingView = -1;
Add scrollListener to all your recyclerviews
mRecyclerView1.addOnScrollListener(scrollListener);
mRecyclerView2.addOnScrollListener(scrollListener);
mRecyclerView3.addOnScrollListener(scrollListener);
your scroll listener should be in this structure. It should decide which recyclerview is giving scroll input and which is receiving.
private RecyclerView.OnScrollListener scrollListener = new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (mRecyclerView1 == recyclerView && newState == RecyclerView.SCROLL_STATE_DRAGGING) {
draggingView = 1;
} else if (mRecyclerView2 == recyclerView && newState == RecyclerView.SCROLL_STATE_DRAGGING) {
draggingView = 2;
} else if (mRecyclerView3 == recyclerView && newState == RecyclerView.SCROLL_STATE_DRAGGING) {
draggingView = 3;
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if (draggingView == 1 && recyclerView == mRecyclerView1) {
mRecyclerView2.scrollBy(dx, dy);
} else if (draggingView == 2 && recyclerView == mRecyclerView2) {
mRecyclerView1.scrollBy(dx, dy);
} else if (draggingView == 3 && recyclerView == mRecyclerView3) {
mRecyclerView1.scrollBy(dx, dy);
}
}
};
Thats all, your recyclerview is ready to scroll. If you scroll one recycleview, it will scroll all other recyclerviews.
Moving is not a problem, stopping is. If user flinged a list, at the same time if he stopped other list, that list will only be stopped, So you need to cover that case too. I hope this explanation and code will solve your problem.

- 2,111
- 18
- 21