07-android 单选按钮 RadioButton

在定义单选按钮的时候RadioGroup包含若干颗RadioButton;

目标:掌握RadioGroup类和RadioButton类的使用

 

RadioGroup 类继承结构:

java.lang.Object

   ↳android.view.View
   ↳android.view.ViewGroup
   ↳android.widget.LinearLayout
   ↳android.widget.RadioGroup

LinearLayout属于线性布局,所以对于单选按钮也肯定需要采用一定的布局管理

对于很多语言单选按钮直接定义即可,但在android中RadioGroup定义的知识一个单选按钮的容器,在容器之中要加入多个单选项,这个单选项就是RadioButton

RadioButton类继承结构:

 

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

RadioButton是Button的子类,同时也是CompoundButton的子类

 

 

 

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:orientation="vertical" >


    <TextView

        android:id="@+id/encinfo"

        android:layout_width="fill_parent"

        android:layout_height="wrap_content"

        android:textSize="20px"

        android:text="请选择要使用的文字编码:" />

<RadioGroup                    -->定义选项组

   android:id="@+id/encoding"

   android:layout_width="fill_parent"

   android:layout_height="fill_parent"

   android:orientation="horizontal">     --->水平显示

   <RadioButton          -->定义选项

       android:id="@+id/utf"

       android:checked="true"    ---->默认选中

       android:text="utf编码"/>

   <RadioButton           -->定义选项

       android:id="@+id/gbk"

       android:text="gbk编码"/>

   </RadioGroup>

</LinearLayout>

 

总结:单选钮必须放在RadioGroup中,而每个RadioButton表示单选钮中的内容。每个RadioGroup中包含多个RadioButton.

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值