Android的RadioButton和checkBox的用法-android学习之旅(十九)
RadioButton和checkBox简介
单选按钮(RadioButton)和复选框(CheckBox)都继承了Button,因此属性的设置和Button差不多,只是加了一个android:chencked属性。
用来设置是否被选中。
RadioButton和checkBox的区别
前者如果一组只能只能选中一个,一次通常会与RadioGroup一块使用,后者没有限制。
实例
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:orientation="vertical">
<TableRow android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="性别:"
android:textSize="16px"/>
<RadioGroup
android:orientation="horizontal"
android:id="@+id/rg"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="男"
android:checked="true"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女"
/>
</RadioGroup>
</TableRow>
<TableRow android:layout_height="wrap_content"
android:layout_width="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="喜欢的颜色"
android:textSize="16px"/>
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="红色"/>
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="蓝色"/>
<CheckBox android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="绿色"/>
</TableRow>
<TableRow android:layout_height="match_parent"
android:layout_width="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="show"/>
</TableRow>
</LinearLayout>
效果图
Android的RadioButton和checkBox的用法-android学习之旅(十九)的更多相关文章
- Android的搜索框SearchView的用法-android学习之旅(三十九)
SearchView简介 SearchView是搜索框组件,他可以让用户搜索文字,然后显示.' 代码示例 这个示例加了衣蛾ListView用于为SearchView增加自动补全的功能. package ...
- 【转】 Pro Android学习笔记(十九):用户界面和控制(7):ListView
目录(?)[-] 点击List的item触发 添加其他控件以及获取item数据 ListView控件以垂直布局方式显示子view.系统的android.app.ListActivity已经实现了一个只 ...
- Android学习路线(十九)支持不同设备——支持不同(Android)平台版本号
当最新的Android版本号为你的应用提供着非常棒的APIs时.你却要在很多其它的设备更新之前继续支持老的系统版本号.这篇课程怎样在继续支持低版本号的系统的情况下使用新版本号的高级API. Platf ...
- Android学习笔记(十九)——内容提供器
//此系列博文是<第一行Android代码>的学习笔记,如有错漏,欢迎指正! 内容提供器(Content Provider)主要用于在不同的应用程序之间实现数据共享的功能,它提供了一套完整 ...
- android 学习随笔二十九(自定义监听 )
package com.itheima.momo.dialog; import com.itheima.momo.R; import android.app.AlertDialog; import a ...
- Android的ViewAnimator而它的子类ViewSwitcher-android学习之旅(三十三)
ViewAnimator遗传FrameLayout,重合使用多个组件.可以增加部件数量,然后会有时间切换动画. ViewAnimator及其子类的继承关系 ViewAnimator经常使用属性 Vie ...
- 从零開始学android<mediaplayer自带播放器(视频播放).四十九.>
MediaPlayer除了能够对音频播放之外,也能够对视频进行播放,可是假设要播放视频仅仅依靠MediaPlayer还是不够的.还须要编写一个能够用于视频显示的空间,而这块显示空间要求能够高速的进行G ...
- Android数据库Sqlite-android学习之旅(九)
简介 sqilte是一个轻量级的数据库,满足数据库的基本操作,由于移动端的内存有限,所以sqilte刚好能满足移动端开发的基本要求. 废话不多说,上代码 1.首先介绍一下,sqlite的管理类SQLi ...
- Android学习笔记(十九) OkHttp
一.概述 根据我的理解,OkHttp是为了方便访问网络或者获取服务器的资源,而封装出来的一个工具包.通常的使用步骤是:首先初始化一个OkHttpClient对象,然后使用builder模式构造一个Re ...
随机推荐
- [BZOJ]1042 硬币购物(HAOI2008)
失踪OJ回归. 小C通过这道题mark一下容斥一类的问题. Description 硬币购物一共有4种硬币.面值分别为c1,c2,c3,c4.某人去商店买东西,去了tot次.每次带di枚ci硬币,买s ...
- bzoj2753[SCOI2012]滑雪与时间胶囊 最小生成树
Time Limit: 50 Sec Memory Limit: 128 MBSubmit: 2843 Solved: 993[Submit][Status][Discuss] Descripti ...
- switch 循环中的case理解
case后面的常量表达式是程序的入口,一旦找到入口后,后面的其他的case就没有用了,程序就会继续执行后面的所有代码
- python中模块,包,库的概念
模块:就是.py文件,里面定义了一些函数和变量,需要的时候就可以导入这些模块. 包:在模块之上的概念,为了方便管理而将文件进行打包.包目录下第一个文件便是 __init__.py,然后是一些模块文件和 ...
- JVM基础
1.基础 JDK 将java文件编译成class文件 JRE 包含JVM JVM可以进行内存管理 利用JDK(调用JAVA API)开发了属于我们自己的JAVA程序后,通过JDK中的编译程序(j ...
- Golang学习笔记:goroutine
1.goroutine goroutine是go语言的并发体.在go语言里面能使用go关键字来实现并发. go func() 1.1 概念介绍 goroutine本质上是协程,我刚刚学习的时候就粗略地 ...
- Nginx配置二级目录/路径 映射不同的反向代理和规避IP+端口访问
当配置Nginx来映射不同的服务器 可以通过二级路径来反向代理 来解决一个外网端口实现多个服务访问. 配置如下: server { listen ; server_name demo.domai ...
- Linux文件基本操作
TIP:Tab键可以自动补全命令 首先要了解Linux树形结构 1./- 根每一个文件和目录从根目录开始.只有root用户具有该目录下的写权限.请注意,/root是root用户的主目录,这与/.不一样 ...
- Docker 列出镜像
使用 docker images 显示本地已有的镜像. $ sudo docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu ...
- cassandra 3.x官方文档(5)---探测器
写在前面 cassandra3.x官方文档的非官方翻译.翻译内容水平全依赖本人英文水平和对cassandra的理解.所以强烈建议阅读英文版cassandra 3.x 官方文档.此文档一半是翻译,一半是 ...