First Glance at new Viewpager2 in Android

Exploring ViewPager2 in Android

using recyclerview adapter with viewpager

Siva Ganesh Kantamani
3 min readOct 11, 2019

--

Photo by Max Nelson on Unsplash

We all know how effective recyclerview in loading a list of views. Imagine how useful bringing that robust functionality to view-pager and that’s what view-pager2 is all about.

At some point in time as a mobile developer, we all have to implement swipe-able layout which shows different views or fragments while swiping. Until now we have used view-pager to achieve this, now it’s time to upgrade, the android team has announced the viewpager2 the combination of original view-pager functionality and recyclerview.

Before we start on how to use viewpager2 let me be clear that viewpager2 is still in beta iterations soon stable version is going to be released. That being said let’s start coding

Integration

Viewpager2 is a support library that means we just need to add the following line under the dependencies tag in build.gradle file

implementation "androidx.viewpager2:viewpager2:1.0.0-beta05"

Check here for latest versions

XML code

It is pretty same as viewpager, have a look

<androidx.viewpager2

--

--