这是一个简单的主界面框架。主界面是 MainActivity。其中 11 底部包含了“首页”、“消息”、“笔记”和“我的”四个按钮,分别指向四个 Fragment 界面模块。 已知该项目使用了 ViewPage+Fragment 方式构建,其中“首页”、“消息”、 “笔记”和“我的”都是 Fragment。
一、ViewPage的使用
1.在XLML文件中(activity_main.xml)添加ViewPager,如下方法:
<androidx.viewpager.widget.ViewPager
android:id="@+id/main_viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
在acivity_main.xml文件代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<androidx.viewpager.widget.ViewPager
android:id="@+id/main_viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation&#