`

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.

 

 

 

 

 

分享到:
评论

相关推荐

    android 自定义单选按钮radioButton

    在Android开发中,单选按钮(RadioButton)是用户界面中常用的一种组件,它通常用于提供一组互斥的选择项,用户只能选择其中的一项。本教程将深入探讨如何在Android中自定义RadioButton,使其满足特定的设计需求。 ...

    Android单选按钮RadioButton的使用详解

    Android单选按钮RadioButton的使用详解 Android单选按钮RadioButton是Android中最普通的UI组件之一,它继承了Button类,可以直接使用Button支持的各种属性和方法。RadioButton与普通按钮不同的是,它多了一个可以...

    Android程序源码--单选、多选按钮

    在Android开发中,单选按钮(RadioButton)和多选按钮(CheckBox)是用户界面中常见的交互元素,用于收集用户的选择信息。本资源包含的是关于如何在Android应用中实现这两种控件的源码示例。 首先,单选按钮...

    Android多行多列的单选按钮组的实现

    总的来说,通过灵活地使用布局管理器和`RadioGroup`的特性,我们可以实现复杂的单选按钮组设计,为用户提供更优质的交互体验。这不仅涉及到基本的XML布局知识,还包括对Android事件处理机制的理解,以及对不同布局...

    安卓单选按钮代码

    在安卓开发中,单选按钮(RadioButton)是用户界面中常见的一种组件,它提供了一种在多个选项中选择一个的机制。本实例将深入探讨如何在Android应用中使用单选按钮,通过源代码来理解其工作原理。 首先,我们需要...

    Android 4.0 在GridLayout中模仿RadioButton单选按钮

    在Android开发中,有时我们需要在GridLayout布局中实现类似RadioButton单选功能,这在设计复杂的用户界面时非常有用。本文将详细讲解如何在Android 4.0版本中利用GridLayout模仿RadioButton的单选效果。 首先,了解...

    Android文本框和单选按钮

    在Android应用开发中,文本框(EditText)和单选按钮(RadioButton)是两种常见的用户界面元素,它们在创建交互式用户界面时起着至关重要的作用。文本框用于接收用户的输入,而单选按钮则用于提供多个选项让用户进行...

    android的单选按钮与多选按钮模板

    在Android开发中,单选按钮(RadioButton)和多选按钮(CheckBox)是用户界面中常见的交互元素,用于收集用户的一项或多项选择。本教程将基于提供的模板深入讲解这两种控件的使用方法及其重要性。 首先,单选按钮...

    Android进阶之RadioButton选中值的获取、单选多行

    `RadioButton`作为单选按钮,通常用于提供多个可选项中的一个,而`RadioGroup`则作为一个容器,用来管理这些`RadioButton`,确保一次只能有一个被选中。本篇文章将深入探讨如何在Android中使用`RadioButton`和`...

    android动态加载Radiobutton

    RadioButton是Android中的一个单选按钮组件,属于RadioGroup的一部分。在RadioGroup中,用户只能选择一个RadioButton,而不能同时选择多个。RadioButton通常与Android的CheckedTextView结合使用,用于显示可选的文本...

    Android 学习之- 单选按钮、复选框、状态开关、时钟控件

    在Android开发中,UI设计是不可或缺的一部分,而单选按钮(RadioButton)、复选框(CheckBox)、状态开关(Switch)和时钟控件(Chronometer)是常用的交互元素。这篇文章将深入探讨这些控件的使用方法、功能特性...

    自定义android RadioButton样式

    在Android开发中,RadioButton是用户界面中常见的组件之一,用于实现单选按钮功能。默认的RadioButton样式虽然简单,但有时并不能满足我们对界面美观度和个性化的需求。因此,自定义RadioButton样式是提升应用视觉...

    好看的自定义radiobutton

    RadioButton是Android UI设计中的一种选择控件,通常用于在多个选项中进行单选。默认样式可能较为简单,但通过自定义,我们可以实现更丰富的视觉效果,如改变颜色、形状、动画等。这可以使用自定义视图(Custom View...

    Android---UI篇

    •Android---UI篇---RadioButton(单选按钮) • •Android---UI篇---CheckBox(多选按钮) • •Android---UI篇---ListView之SampleAdapter(列表)---1 • •Android---UI篇---ListView之ArrayAdapter(列表)---2...

    关于接口在android单选按钮下的实现

    通过这种方式,我们实现了在Android单选按钮下使用接口,使得代码更易于理解和维护。这种设计模式在实际项目中非常常见,尤其是在需要解耦组件间交互的场景下。 至于“GoHome”这个文件名,可能是博客文章的HTML...

    Android 动态添加RadioGroup的RadioButton-IT计算机-毕业设计.zip

    RadioButton是Android中的一个视图组件,它提供了一个单选按钮的视觉表示。用户只能选择其中一个RadioButton,当一个RadioButton被选中时,其他同组内的RadioButton会自动取消选中。 3. **动态添加RadioButton**:...

    单选按钮(RadioButton)和复选框(CheckBox)

    在Android开发或者GUI编程中,单选按钮(RadioButton)和复选框(CheckBox)是两种常用的用户界面元素,用于收集用户的二进制选择信息。它们都属于选择控件,但功能上有所不同,提供了不同的交互方式。 单选按钮...

    Android开发之RadioButton位于文字右边的显示方法

    在Android开发中,RadioButton是单选按钮控件,通常用于在多个选项中让用户选择一个。默认情况下,RadioButton的图标(一个小圆圈)位于文字的左边。然而,根据UI设计的需求,有时我们可能希望将RadioButton的图标...

Global site tag (gtag.js) - Google Analytics