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> Instead of FrameLayout, we put the ViewPager view. Then, open the MainActivity class and update it like this:
class MainActivity : BaseActivity(...