此功能是在上一篇博客的基础上进行改进,增加了底部切换标签,此处是使用Fragment,底部使用radioGroup+radioButton,添加5个子fragment到该Fragment
在这个小案例中添加了一些小细节:
1.将不需要有侧滑菜单的子Fragment进行隐藏侧滑图标
2.定义一个方法使该页面真正不能有侧滑菜单
3.更改各个子Fragment的标题
4.自定义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"
android:orientation="vertical">
<com.jhy.drawerlayoutdemo.CustomViewPager
android:id="@+id/vp_content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</com.jhy.drawerlayoutdemo.CustomViewPager>
<RadioGroup
android:id="@+id/rg_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/rb_home"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="@null"
android:drawableTop="@mipmap/ic_launcher"
android:gravity="center"
android:textColor="#9b979a"
and