RadioButton+Fragment实现简单主页面布局
实现主页面布局的方法有不少,很常见的有ViwePager+Fragment,还有TabHost等等,这里因为主页面不需要滑动,也可以用RadioButton+Fragment实现简单的主页布局。为了区分每个页面的不同,随便添加了几个控件,先上效果图:
主页面就是一个Framlayout+RadioGroup,通过点击下边的按钮,切换Fragment。代码非常简单,下面贴出来:
<?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:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.gechao.materialtabsdemo.MainActivity">
<FrameLayout
android:id="@+id/fm"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"></FrameLayout>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#0099FF"
android:gravity="center_vertical"
android:orientation="h