RadioGroup的一些操作总结

一、子RadioButton里涉及到android:state_focused 与 android:state_checked时注意两个状态的处理顺序,否则会出现Group里的控件背景状态错乱。以下为个人实验可行selector:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/index_djzx_pressed" android:state_focused="false" android:state_checked="true"/>
    <item android:drawable="@drawable/index_djzx_focusedc" android:state_focused="true" android:state_checked="true"/>
    <item android:drawable="@drawable/index_djzx_focused" android:state_focused="true" android:state_checked="false"/>
    <item android:drawable="@drawable/index_djzx"/>
</selector>

二、在代码中控制RadioGroup的选择其中的某个子RadioButton:利用check(资源id)方式

		mrbtngroup_Navigation = (RadioGroup)findViewById(R.id.rbtngroup_Navigation);
				mrbtngroup_Navigation.check(R.id.index_djzx_btn);


三、取消RadioGroup内的所有RadioButton的选中状态:处理方式为利用RadioGroup的check(id)的方法,将RadioGroup的check状态指向一个非RadioGroup内子控件的id:

方法如下:

				mrbtngroup_Navigation.check(R.id.index_setting_btn);

另外附上页面Xml的RadioGroup部分布局的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="75px"
    android:paddingTop="15px"
    android:gravity="center_vertical"
    android:layout_gravity="center_vertical"
    android:orientation="horizontal">
	<RadioGroup 
	    android:id="@+id/rbtngroup_Navigation"
	    android:layout_width="wrap_content"
	    android:layout_height="75px"
       android:layout_marginLeft="45px"
       	android:layout_marginRight="75px"
       	android:orientation="horizontal"
    	android:gravity="center_vertical"
    	android:layout_gravity="center_vertical">
	    
    <RadioButton
        android:id="@+id/index_djzx_btn"
        android:layout_width="120px"
        android:tag="topmenu1"
       	android:layout_height="38px"
       	android:layout_marginLeft="50px"
       	android:button="@null"
       	android:background="@drawable/index_djzx_select"
       	android:nextFocusRight="@+id/index_dwgl_btn"
       	android:nextFocusLeft="@+id/index_search_btn"
       	android:onClick="switchColumn"/>
       
    
    <RadioButton
        android:id="@+id/index_dwgl_btn"
        android:layout_width="120px"
        android:tag="topmenu2"
       	android:layout_height="38px"
       	android:layout_marginLeft="50px"
       	android:button="@null"
       	android:background="@drawable/index_dwgl_select"
       	android:nextFocusLeft="@+id/index_djzx_btn"
       	android:nextFocusRight="@+id/index_dyjy_btn"
       	android:onClick="switchColumn"/>
       
    
    <RadioButton 
        android:id="@+id/index_dyjy_btn"
        android:tag="topmenu3"
        android:layout_width="120px"
       	android:layout_height="38px"
       	android:layout_marginLeft="50px"
       	android:button="@null"
       	android:checked="true"
       	android:background="@drawable/index_dyjy_select"
       	android:nextFocusLeft="@+id/index_dwgl_btn"
       	android:nextFocusRight="@+id/index_zwfw_btn"
       	android:onClick="switchColumn"/>
       
    
    <RadioButton 
        android:id="@+id/index_zwfw_btn"
        android:layout_width="120px"
        android:tag="topmenu4"
       	android:layout_height="38px"
       	android:layout_marginLeft="50px"
       	android:button="@null"
       	android:background="@drawable/index_zwfw_select"
       	android:nextFocusLeft="@+id/index_dyjy_btn"
       	android:nextFocusRight="@+id/index_bmfw_btn"
       	android:onClick="switchColumn"/>
       
    
    <RadioButton 
        android:id="@+id/index_bmfw_btn"
        android:layout_width="120px"
        android:tag="topmenu5"
       	android:layout_height="38px"
       	android:layout_marginLeft="50px"
       	android:button="@null"
       	android:background="@drawable/index_bmfw_select"
       	android:nextFocusLeft="@+id/index_zwfw_btn"
       	android:nextFocusRight="@+id/index_setting_btn"
       	android:onClick="switchColumn"/>
	</RadioGroup>
    
       
    <!-- 设置 -->

    <Button
        android:id="@+id/index_setting_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="184px"
        android:visibility="gone"
        android:background="@drawable/index_setting_select"
        android:nextFocusLeft="@+id/index_bmfw_btn"
        android:nextFocusRight="@+id/index_search_btn"
        android:onClick="switchColumn"
        android:tag="topmenu6" />
    
    
     <!-- 搜索 -->

    <Button
        android:id="@+id/index_search_btn"
        android:layout_width="35px"
        android:layout_height="38px"
        android:layout_marginLeft="30px"
        android:visibility="gone"
        android:background="@drawable/index_search_select"
        android:nextFocusLeft="@+id/index_setting_btn"
        android:nextFocusRight="@+id/index_djzx_btn"
        android:onClick="startColumnActivity"
        android:tag="topmenu6" />

</LinearLayout>




  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值