Android学习|视图翻页——ViewPager
简单效果
实现
1、activity_main.xml中添加ViewPager
当ViewPager中没有视图时,为空白的
<?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">
<androidx.viewpager.widget.ViewPager
android:id="@+id/vp"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.viewpager.widget.ViewPager>
</LinearLayout>
2、做多个xml作为要添加的View
其他view自行修改
<?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">
<TextView
android:text="Layout 1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize