O'Reilly logo

Mastering Android Application Development by Antonio Pachón Ruiz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

ViewPager

Continuing with our example, we have two ways of navigating between fragments on MainActivity: either by tapping on the tabs or by swiping between the fragments. To achieve this, we will use ViewPager, including the sliding tabs inside it, which is a very elegant solution with minimal code and includes synchronization between swipe and tabs.

ViewPager can be used to slide any kind of view. We could create a gallery of images with ViewPager; it is very common to see tutorials in the first run of some apps where you can slide the screen with instructions on how the app works, and this is achieved with ViewPager. To add ViewPager to MainActivity, we can simply copy and paste the following code:

<?xml version="1.0" encoding="utf-8"?> <android.support.v4.view.ViewPager ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required