04 RadioGroup

本文介绍了Android中RadioGroup和RadioButton的基本概念与使用方法。RadioGroup作为容器组件,用于容纳多个RadioButton实现单选功能,通过LinearLayout进行布局管理。文章详细阐述了如何在XML中定义这些组件,并展示了具体的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 1. RadioGroup和RadioButton:

   在HTML中,<input type="radio">


java.lang.Object
    |-android.view.View
 	   |-android.view.ViewGroup
 	 	   |-android.widget.LinearLayout
 	 	 	   |-android.widget.RadioGroup

2. RadioGroup 单选钮在开发中提供了 一种多选一的操作模式。

  LinearLayout属于布局管理器,所以对于单选按钮而言肯定也要采用一定的布局管理。

3. 对于很多语言的单选钮直接定义即可,但是在android中,RadioGroup定义的只是一个
单选钮的容器,在这个容器中以后要加入多个单选项,而这个单选项就是RadioButton。


4. RadioButton:

java.lang.Object
   |-android.view.View
 	   |-android.widget.TextView
 	 	   |-android.widget.Button
 	 	 	   |-android.widget.CompoundButton
 	 	 	 	   |-android.widget.RadioButton




  <RadioGroup
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:checkedButton="@+id/male1">
        
        <RadioButton
          android:id="@+id/male1"
          android:text="@string/namemale"/>

      <RadioButton
          android:id="@+id/female1"
          android:text="@string/namefemale"/>
         
       </RadioGroup>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值