I am novice to android studio and I want to make a 2 or 3 layer of cardview in one recyclerview or gridlayout/gridview that can scroll horizontally, but I can't find any tutorial about it. Can someone please help me on how can i make it.
Basically the idea is when the user scrolled to the left, both or all the layers of products will slide at the same time.
First you need to create a new OnScrollListener
to be able to detect how much you scrolled your recycler view by using onScrolled
callback method.
and then you need to pass dx and dx int values to your another Recyclerview in order to scroll it simultaneously with your dragged Recyclerview
your new onScrollListener should seems like below
RecyclerView.OnScrollListener scrollListener = new RecyclerView.OnScrollListener {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
scrollAllRecyclerView(recyclerView, dx, dy);
}
private void scrollAllRecyclerView(RecyclerView recyclerView, int dx, int dy) {
scroll(dx, dy)
}
}
private void scroll(int dx, int dy) {
recyclerView.removeOnScrollListener(this);
recyclerView.scrollBy(dx, dy);
recyclerView.addOnScrollListener(this);
}
anotherRecyclerView.scrollBy(dx, dy);