I have recycler view with adapter. Need deny user to scroll to item with 0 index, when it was scrolled. F.e user scrolls to 5 item and when scrolls back first visible will be item with index 1. Will be glad any ideas how to implement this feature.
Asked
Active
Viewed 47 times
-3
-
Check my answer below.It will suffice your need – Koustuv Ganguly May 15 '18 at 12:33
-
I think the best way to handle this is by removing the item at index 0 (the one you don't want to display it and then put it back to the same location when needed.. this will help you avoid hacking your way around the user interaction – ColdFire May 15 '18 at 12:46
-
Its to easy remove 0 item, but I cannot notify adapter because of many some issues, connected with notify and own custom layout manager. – Ruslan Podurets May 17 '18 at 12:06
1 Answers
0
Use smoothScrollToIndex(1)
inside addOnScrollListener
of the recycler view.
Keep a if check with !recyclerView.canScrollVertically(-1)
there if it succeeded then use like :
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if(!recyclerView.canScrollVertically(-1))
{
mRecyclerView.smoothScrollToIndex(1);
}
}});

Koustuv Ganguly
- 897
- 7
- 21