Check Mobile App
Read now
Start a Project

ViewPager2 in Android


ViewPager2 replaces ViewPager, addressing most of its predecessor’s pain-points, including right-to-left layout support, vertical orientation, modifiable Fragment collections, etc. Now its stable version is also released.

To use ViewPager2 in your projects, you need to add the following dependencies in your build.gradle file :

To add ViewPager2 in your layout, add the following code in your layout’s XML file :

If you check the implementation of ViewPager2, it uses RecyclerView within. Thus if you’ve implemented RecyclerView, implementing ViewPager2 wouldn’t be much different.

You can use fragments inside ViewPager2 same as we do in ViewPager.

You just need to use FragmentStateAdapter instead of FragmentStatePagerAdapter.

In order to register a Listener on ViewPager2, we need to do the following:

To set scroll orientation we need to do the following:


Example of an adapter for the same:



. . .

Leave a Comment

Your email address will not be published. Required fields are marked*

Be the first to comment.


The support is fast and do everything in their power to make it perfect. If you need customization it's also done right away. I had massive research to select Mobikul and now I'm sure it was the right one.

Igor Souza

Igor Souza

Talk to Sales


Live Chat
Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home