RadioButton是一个按钮,是一组按钮,它的作用是用来切换的,
在实际的项目中,我们经常都是RadioButton
和RadioGroup
一起配合使用。RadioGroup
是单选组合框,可以容纳多个RadioButton
的容器。在没有RadioGroup
的情况下,RadioButton
可以全部都选中;当多个RadioButton
被RadioGroup
包含的情况下,RadioButton
只可以选中一个。并用setOnCheckedChangeListener
来对单选按钮进行监听。众所周知,RadioGroup
只能够通过设置radioGroup.setOrientation()
实现纵向或者横向排列,并且只能是一列或者一行,并且RadioGroup
中还只能直接放RadioButton
,但在实际项目中我们大都是需要实现上面的效果,所以简单的封装了一个,取名为: XRadioGroup 。那么为了做出这个底部导航的效果,我们看具体一步一步来实现:首先中间要准备显示的内容就是四个布局,那么这四个布局靠的就是一个帧布局,,,但是这四个小的布局不能够全部写在帧布局里面把,如果全部都写在里面那么可能就会出现,如果全部写在里面那么,布局就太大了,太复杂了,底部就是四个按钮,就是上面这一组radioButton,也是一个布局:首先我们来创建下面一组布局:一、创建底部的RadioButton布局<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <RadioGroup android:id="@+id/group12" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <RadioButton android:id="@+id/radioButton2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="RadioButton" /> <RadioButton android:id="