I just want to allow only scroll left in horizontal recyclerview for example. Please help me on that
Question posted in Android Studio
The official documentation can be found here.
The official documentation can be found here.
I just want to allow only scroll left in horizontal recyclerview for example. Please help me on that
2
Answers
Best way is to remove other directions item from adapter, which are getting hidden one by one. So when user scroll back ward it will not show up any thing.
I would not touch the data in your adapter (what does the data have to do with a UI business rule?). If you want, you could notify your Repository or ViewModel what views have been "scrolled" but that’s a lot of events going up, and state coming down for everyone involved.
You have the tools at your disposal in the form of a combination of:
GestureDetector
(See (the documentation.)TouchListener
(See (the documentation.)or perhaps benefit from the somewhat modular approach of RecyclerView:
Using
OnItemTouchListener
and aOnScrollListener
to analyze the events and ignore the ones you don’t want.You could also create your own extended RecyclerView but that’s more painful because you now need to change it all over the place you want this behavior.
In any case, your search engine of choice is also a good starting point. But think of this as:
You will need to intercept the touches and flings gestures (as well as other motion actions like "Dpads" and other Accessibility Events that may trigger a "scroll", evaluate in which direction this is headed, and determine if you still want that event to happen.