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
MainActivity, we can simply copy and paste the following code:
<?xml version="1.0" encoding="utf-8"?> <android.support.v4.view.ViewPager ...