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学习之旅(十九)的更多相关文章

  1. Android的搜索框SearchView的用法-android学习之旅(三十九)

    SearchView简介 SearchView是搜索框组件,他可以让用户搜索文字,然后显示.' 代码示例 这个示例加了衣蛾ListView用于为SearchView增加自动补全的功能. package ...

  2. 【转】 Pro Android学习笔记(十九):用户界面和控制(7):ListView

    目录(?)[-] 点击List的item触发 添加其他控件以及获取item数据 ListView控件以垂直布局方式显示子view.系统的android.app.ListActivity已经实现了一个只 ...

  3. Android学习路线(十九)支持不同设备——支持不同(Android)平台版本号

    当最新的Android版本号为你的应用提供着非常棒的APIs时.你却要在很多其它的设备更新之前继续支持老的系统版本号.这篇课程怎样在继续支持低版本号的系统的情况下使用新版本号的高级API. Platf ...

  4. Android学习笔记(十九)——内容提供器

    //此系列博文是<第一行Android代码>的学习笔记,如有错漏,欢迎指正! 内容提供器(Content Provider)主要用于在不同的应用程序之间实现数据共享的功能,它提供了一套完整 ...

  5. android 学习随笔二十九(自定义监听 )

    package com.itheima.momo.dialog; import com.itheima.momo.R; import android.app.AlertDialog; import a ...

  6. Android的ViewAnimator而它的子类ViewSwitcher-android学习之旅(三十三)

    ViewAnimator遗传FrameLayout,重合使用多个组件.可以增加部件数量,然后会有时间切换动画. ViewAnimator及其子类的继承关系 ViewAnimator经常使用属性 Vie ...

  7. 从零開始学android&lt;mediaplayer自带播放器(视频播放).四十九.&gt;

    MediaPlayer除了能够对音频播放之外,也能够对视频进行播放,可是假设要播放视频仅仅依靠MediaPlayer还是不够的.还须要编写一个能够用于视频显示的空间,而这块显示空间要求能够高速的进行G ...

  8. Android数据库Sqlite-android学习之旅(九)

    简介 sqilte是一个轻量级的数据库,满足数据库的基本操作,由于移动端的内存有限,所以sqilte刚好能满足移动端开发的基本要求. 废话不多说,上代码 1.首先介绍一下,sqlite的管理类SQLi ...

  9. Android学习笔记(十九) OkHttp

    一.概述 根据我的理解,OkHttp是为了方便访问网络或者获取服务器的资源,而封装出来的一个工具包.通常的使用步骤是:首先初始化一个OkHttpClient对象,然后使用builder模式构造一个Re ...

随机推荐

  1. hdu 5489(LIS最长上升子序列)

    题意:一个含有n个元素的数组,删去k个连续数后,最长上升子序列        /*思路参考GoZy 思路: 4 2 3 [5 7 8] 9 11 ,括号表示要删掉的数, 所以  最长上升子序列  = ...

  2. Frame buffer分析 - fbmem.c【转】

    转自:http://www.cnblogs.com/armlinux/archive/2012/03/01/2396753.html 45 struct fb_info *registered_fb[ ...

  3. flask jQuery ajax 上传文件

    1.html 代码 <div> <form id="uploadForm" enctype="multipart/form-data" > ...

  4. 120. Triangle(中等)

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

  5. Ubuntu搭建owncloud10

    前言: 在此我先吐槽一下.用Centos系统简直是为难我自己,是看到那个系统 感到无比的绝望. 正文: 自己在虚拟机中搭建Ubuntu系统.这里就不说了 安装好之后自己换源.建议的源: 清华源: # ...

  6. 关于mysql安装到最后一步老是停留在starting server,显示无响应

    从昨天晚上到今天安装MySQL花了好长的时间,一直是在后面starting server 这部就显示无响应,查资料了解到是MySQL有残留,有些注册表文件需要手动清理,下面是具体方法. 1.先用卸载软 ...

  7. 韩顺平玩转Oracle视频资料整理

    .oracle10g 11g:g(grid)表示网格技术 以baidu搜索为准,现在想使用一个软件,但是此软件在离自己非常近的地方就存在了下载地址,但是与自己非常远的地方也同样存在一个下载地址,而搜索 ...

  8. Python 3.3.2 round函数并非"四舍五入"

    对于一些貌似很简单常见的函数,最好还是去读一下Python文档,否则当你被某个BUG折磨得死去活来时,还不知根源所在.尤其是Python这种不断更新的语言.(python 2.7 的round和3.3 ...

  9. cassandra 3.x官方文档(6)---内部原理之存储引擎

    写在前面 cassandra3.x官方文档的非官方翻译.翻译内容水平全依赖本人英文水平和对cassandra的理解.所以强烈建议阅读英文版cassandra 3.x 官方文档.此文档一半是翻译,一半是 ...

  10. Android自定义View实战(SlideTab-可滑动的选择器)

    转载请标明出处: http://blog.csdn.net/xmxkf/article/details/52178553 本文出自:[openXu的博客] 目录: 初步分析重写onDraw绘制 重写o ...