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 3963 [WF2011]MachineWorks
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=3963 题解: 斜率优化DP,CDQ分治. 先按时间排序.(规定以下内容的第i台机器的卖出时间 ...
- 2015 多校联赛 ——HDU5414()
Problem Description CRB has two strings s and t. In each step, CRB can select arbitrary character c ...
- quartzJob 例子
KpiOfPoorQualityJob.javapackage com.eastcom_sw.inas.workorder.quartzJob.kpi; import net.sf.json.JSON ...
- sklearn.model_selection 的 train_test_split作用
train_test_split函数用于将数据划分为训练数据和测试数据. train_test_split是交叉验证中常用的函数,功能是从样本中随机的按比例选取train_data和test_data ...
- HttpServletRequest获取URL?后面的内容
获取URL?后面的内容 如https://i.cnblogs.com/EditPosts.aspx?opt=1 String para = request.getQueryString(): para ...
- js匿名函数,闭包
http://www.cnblogs.com/chenxianbin89/archive/2010/01/28/1658392.html
- 开发一个 app 有多难?
171 个回答 默认排序 道衍天机 有事情的加微信1293190838找我 1,150 人赞同了该回答 ----------------------------------------------- ...
- Docker常见仓库MongoDB
MongoDB 基本信息 MongoDB 是开源的 NoSQL 数据库实现. 该仓库提供了 MongoDB 2.2 ~ 2.7 各个版本的镜像. 使用方法 默认会在 27017 端口启动数据库. $ ...
- 整理的Java List Set Map是否有序,元素是否允许重复
整理的Java List Set Map是否有序,元素是否允许重复的说明,如下图:
- Android系统对话框
Android系统对话框 效果图 2个按钮的对话框 3个按钮的对话框 自定义View的对话框 单选对话框 多选对话框 列表框 Code XML <?xml version="1.0&q ...