效果图:
实现步骤:
1.首先在app的builde文件中引用ViewPager2
implementation 'androidx.viewpager2:viewpager2:1.0.0-alpha01'
2.添加首页的布局xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/mainViewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/navigationView" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/navigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="tru