I want to use right and left buttons to scroll items with like 10 items
I tried to use scrollBy but it did not work
Here is my Layout Image.
I want to use right and left buttons to scroll items with like 10 items
I tried to use scrollBy but it did not work
Here is my Layout Image.
You can use for Next button:
mRecyclerView.getLayoutManager().scrollToPosition(linearLayoutManager.findLastVisibleItemPosition() + 1);
And for Previous Button:
mRecyclerView.getLayoutManager().scrollToPosition(linearLayoutManager.findFirstVisibleItemPosition() - 1);
Have look this
You can have a variable that tracks the current displayed position of the RecyclerView, named it "currentPosition" in below snippets
Then increment it if you want to navigate to the next item as follows:
private void scrollToNext() {
if ((recyclerView.getLayoutManager()) != null) {
((LinearLayoutManager) recyclerView.getLayoutManager()).scrollToPositionWithOffset(currentPosition++, 0);
}
}
You can use RelativeLayout
or the custom layout instead of LinearLayout
; according to what you're using in your RecyclerView
Similarly, decrement it if you want the previous one
private void scrollToPrevious() {
if ((recyclerView.getLayoutManager()) != null) {
((LinearLayoutManager) recyclerView.getLayoutManager()).scrollToPositionWithOffset(currentPosition--, 0);
}
}