With LinearSnapHelper
, this is now very easy.
All you need to do is this:
SnapHelper helper = new LinearSnapHelper();
helper.attachToRecyclerView(recyclerView);
It’s that simple! Note that LinearSnapHelper
was added in the Support Library starting from version 24.2.0.
Meaning you have to add this to your app module’s build.gradle
compile "com.android.support:recyclerview-v7:24.2.0"
Edit: AndroidX LinearSnapHelper