一.创建activity文件
1.创建一个activity名为view pagerMainActivity 文件,并生成一个activity_view pager_main.xml文件,其中activity_view pager_main.xml文件代码为
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".viewpageMainActivity">
<androidx.viewpager2.widget.ViewPager2
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/viewpage"/>
</LinearLayout>
这里我用的是view pager2,需要加载dependence
在其中dependence是中添加
implementation 'androidx.vi