how to make horizontal scrolling like google play in android?

RecyclerView usually used to show the list or any collections. Recycler View has an own scroll behaviour vertically or horizontally. For this, we have to define LayoutManager for layout behaviour. Here I am giving an example how RecyclerView declares and add layout manager:

RecyclerView rvBotCollection;
rvBotCollection =(RecyclerView)itemView.findViewById(R.id.rvCollectionList);

Then an adapter will add to show the whole list with item view. Now we can make it horizontally scroll-able like this:

rvBotCollection.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));

Now RecyclerView will scroll in a horizontal way. But the main problem is view will scroll at a time multiple items. Using SnapHelper we can make single item scroll at a time like this way:

SnapHelper snapHelper = new PagerSnapHelper();
snapHelper.attachToRecyclerView(rvBotCollection);

This two line will do the magic.


The support library now includes two different classes for this behavior.

LinearSnapHelper linearSnapHelper = new LinearSnapHelper();
linearSnapHelper.attachToRecyclerView(recyclerView);

That's it.

If you want more customization you need to extend the LinearSnapHelper or PagerSnapHelper and override calculateDistanceToFinalSnap method.