1、主界面xml文件
依赖 implementation 'androidx.viewpager2:viewpager2:1.0.0'
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewPager"
android:background="@color/teal_700"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
2、viewpager要显示的UI界面的xml文件