Creating View Pager

As we mentioned, we want our items to display on several pages that can be swiped. To do so, we need ViewPager. ViewPager makes it possible to swipe between different fragments as a part of the fragment collection. We will make some changes to our code. Open the activity_main layout and update it like this:

    <?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android=     "http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 
    <android.support.v4.view.ViewPager  xmlns:android= "http://schemas.android.com/apk/res/android" android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> ...

Get Mastering Android Development with Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.