一、RadioButton和RadioGroup:

  RadioButton是单个的圆形单选框,而RadioGroup是可以容纳多个RadioButton存在的容器,因此RadioButton和RadioGroup往往都配合使用。

  每个已经放入RadioGroup中的RadioButton只能有一个被选中,不放入RadioGroup中的RadioButton可以多选,和checkbox无异。

  1、简单实例:

<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"> <RadioButton
android:id="@+id/buttonSchool1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/school1"
android:checked="true"/> <RadioButton
android:id="@+id/buttonSchool2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/school2"/> <RadioButton
android:id="@+id/buttonSchool3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/school3"/> <RadioButton
android:id="@+id/buttonSchool4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/school4"/> </RadioGroup>

  运行结果如下:

  

  2、RadioGroup基本属性:

  (1)、orientation:排列方式

      若值为horizontal,则为横向,水平排列:

      android:orientation="horizontal"

      

      

      若值为vertical,则为纵向,垂直排列。

      android:orientation="vertical"

      

      

    (2)、checkedButton:默认选中

      直接调用已经放入在radiogroup中且已有id的radiobutton即可默认选中此项。

      android:checkedButton="@+id/buttonSchool2"

      

      

  3、RadioButton基本属性:

    (1)、checked:选中状态

      若为true则默认被选中,false则默认不被选中。

      

      

    (2)、text等相关属性:

      text是按钮的文本内容;

      textSize是文本字体大小;

      textColor是文本字体颜色······

      这些属性和TextView一致。

      

      

    (3)、button:按钮属性

      若button的值设为“@null”则不显示前面的圆形按钮,只显示文本内容本身

      android:button="@null"

      

      

 二、CheckBox:

  1、简单实例:

    <CheckBox
android:text="@string/school1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/checkBox" /> <CheckBox
android:text="@string/school2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/checkBox"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="19dp"
android:id="@+id/checkBox2" /> <CheckBox
android:text="@string/school3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/checkBox2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="23dp"
android:id="@+id/checkBox3" />

  

  2、基本属性:

  checkbox和radiobutton的属性基本一致。

    (1)、checked:是否被默认选中

      android:checked="true"

      

      

    (2)、text等相关属性:

      

      

    (3)、button:按钮属性

      若button的值设为“@null”则不显示前面的方形按钮,只显示文本内容本身

      

      button属性对按钮的设置可以搭配drawable对按钮的样式进行修改和美化。

 三、CheckBox和RadioButton区别:

RadioButton CheckBox
选中后,通过点击无法变为未选中  选中后,通过点击可以变为未选中
只能同时选中一个 能同时选中多个
大部分UI框架中,默认圆形表示 大部分UI框架中,默认方形表示
 
 

      

Android开发:文本控件详解——RadioButton和CheckBox(一)基本属性的更多相关文章

  1. Android开发:文本控件详解——TextView(一)基本属性

    一.简单实例: 新建的Android项目初始自带的Hello World!其实就是一个TextView. 在activity_main.xml中可以新建TextView,从左侧组件里拖拽到右侧预览界面 ...

  2. Android开发:文本控件详解——EditText(一)基本属性

    一.简单实例: EditText输入的文字样式部分的属性,基本都是和TextView中的属性一样. 除此之外,EditText还有自己独有的属性. 二.基本属性: hint  输入框显示的提示文本  ...

  3. Android开发:文本控件详解——TextView(二)文字跑马灯效果实现

    一.需要使用的属性: 1.android:ellipsize 作用:若文字过长,控制该控件如何显示. 对于同样的文字“Android开发:文本控件详解——TextView(二)文字跑马灯效果实现”,不 ...

  4. IOS—UITextFiled控件详解

    IOS—UITextFiled控件详解 //初始化textfield并设置位置及大小 UITextField *text = [[UITextField alloc]initWithFrame:CGR ...

  5. Switch控件详解

    Switch控件详解 原生效果 5.x 4.x 布局 <Switch android:id="@+id/setting_switch" android:layout_widt ...

  6. ToolBar控件详解

    ToolBar控件详解 在Activity中添加ToolBar 1.添加库 dependencies { ... compile "com.android.support:appcompat ...

  7. Spinner控件详解

    Spinner控件详解 效果图 修改Spinner样式 在介绍之前,先看一下系统原生的样式 6.x & 5.x系统样式 4.x系统样式 官方文档 XML属性 方法 描述 android:dro ...

  8. CAD控件,CAD插件使用教程:Android开发使用控件--开发环境的搭建

    Android开发使用控件入门--环境搭建 2014-12-24 09:57     14人阅读     评论(0)     收藏         编辑     删除 CAD控件.CAD三维控件,手机 ...

  9. Android开发使用控件入门--环境搭建

    Android开发使用控件入门--环境搭建 软件名称(,梦,,想.CAD  ,控件) 1. 环境搭建: 3 1.1. 安装Eclipse 3 1.2. 下载JDK 3 1.3. 下载Android S ...

随机推荐

  1. docker搭建elasticsearch、kibana,并集成至spring boot

    步骤如下: 一.基于docker搭建elasticsearch环境 1.拉取镜像 docker pull elasticsearch5.6.8 2.制作elasticsearch的配置文件 maste ...

  2. 我碰到的stackoverflow error

    出现这种问题,首先需要检查自己的代码: 要么代码小错误:或者逻辑错误: 如果出现循环调用更要仔细检查: 我的问题: 循环调用:一个实体他有自己的父栏目,含有子栏目的list集合:两者结果映射resul ...

  3. Date+闭包

    date类: var  time=new.date() get date() 返回一个月中的某一天 get day () 返回一周中的某一天 get fullyear() 对象以四位数返回年份 get ...

  4. Springboot vue.js html 跨域 前后分离 Activiti6 shiro 权限

    官网:www.fhadmin.org 特别注意: Springboot 工作流  前后分离 + 跨域 版本 (权限控制到菜单和按钮) 后台框架:springboot2.1.2+ activiti6.0 ...

  5. java开发中,一些小的JS应用

    js中打开一个新窗口的方法: 1.window.location.href=“url” 2.jbox.win(); 3.window.open(); js无任何提示的关闭弹出的页面: window.o ...

  6. Golang: 常用的文件读写操作

    Go 语言提供了很多文件操作的支持,在不同场景下,有对应的处理方式,今天就来系统地梳理一下,几种常用的文件读写的形式. 一.读取文件内容 1.按字节读取文件 这种方式是以字节为单位来读取,相对底层一些 ...

  7. 洛谷 P1330 封锁阳光大学题解

    题目描述 曹是一只爱刷街的老曹,暑假期间,他每天都欢快地在阳光大学的校园里刷街.河蟹看到欢快的曹,感到不爽.河蟹决定封锁阳光大学,不让曹刷街. 阳光大学的校园是一张由N个点构成的无向图,N个点之间由M ...

  8. 前端模板引擎artTemplate.js

    . 关于artTemplate模板引擎的详细原理请移步高性能JavaScript模板引擎原理解析,本文只探讨如何使用.初学前端的人一般对于绑定数据都是使用原生js或者jquery来拼接字符串,此为ha ...

  9. 项目Beta冲刺(团队)--2/7

    课程名称:软件工程1916|W(福州大学) 作业要求:项目Beta冲刺 团队名称:葫芦娃队 作业目标:进行新一轮的项目冲刺,尽力完成并完善项目 团队博客 队员学号 队员昵称 博客地址 04160242 ...

  10. 第一章 Java起源

    1.计算机语言发展史:B语言-->C语言-->C++语言-->Java语言.通过C和C++反过来理解Java的设计,理解更深: 复杂性:结构化变成=>面向对象编程:继承.封装. ...