Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I use
attachToRecyclerView(RecyclerView)
and it works as expected.
Question: at some point I want the same recyclerView to scroll normally, how to achieve that?
Code:
PagerSnapHelper pagerSnapHelper = new PagerSnapHelper();
pagerSnapHelper.attachToRecyclerView(recyclerView);
–
–
Staring from recyclerview-v7:25.1.0
, is enough to call
snapHelper.attachToRecyclerView(null);
to remove the SnapHelper
I faced the same problem. Calling
clearOnScrollListeners();
setOnFlingListener(null);
on the RecyclerView
instance did the trick for me. Calling only setOnFlingListener(null);
wasn't enough in my case
well,it's written on the SnapHelper official API:Public methods=>attachToRecyclerView:[The RecyclerView instance to which you want to add this helper or null if you want to remove SnapHelper from the current RecyclerView.]
https://developer.android.com/reference/android/support/v7/widget/SnapHelper.html#attachToRecyclerView%28android.support.v7.widget.RecyclerView%29
–
If you don't want to keep the reference of SnapHelper then there is another way around as per the official documentation you can use
recyclerView.setOnFlingListener(null);
From the Android documentaion
Attaches the {@link SnapHelper} to the provided RecyclerView, by calling
{@link RecyclerView#setOnFlingListener(RecyclerView.OnFlingListener)}.
You can call this method with {@code null} to detach it from the current RecyclerView.
Caution
SnapHelper.attachToRecyclerView() can throw IllegalArgumentException
@throws IllegalArgumentException if there is already a {@link RecyclerView.OnFlingListener}
attached to the provided {@link RecyclerView}.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.