实现类似微信的效果,点击手机底部的标签时切换至对应的内容界面
思路:
- 需要为每个标签设置对应的fragment界面 编写相应的逻辑代码
- 点击标签时切换相对应的fragment界面
项目代码结构
1. 编写主界面的xml布局文件
- activity.main
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".MainActivity">
<!-- 展示内容界面-->
<LinearLayout
android:id="@+id/content_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/>
<!-- 展示切换标签-->
<LinearLayout
android:id="@+id/layout_bottom"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
<RadioGroup
android:id="@+id/rg_home"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_blue_dark"
android:orientation="horizontal">
<RadioButton
android:id="@+id/rb_1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"