转载出处:http://sunzone.iteye.com/blog/1859325
<!--
单选按钮操作测试:
1、单选按钮:RadioButton 需要配合 RadioGroup 进行使用,RadioGroup 是 RadioGroup 的承载体
2、每一组RadioGroup 里面只能有一个RadioButton 被选中,不同的组之间互不影响;
3、一个RadioGroup 里面至少包含两个RadioButton , 能包含多个单选按钮;
4、每一组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:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="单选按钮测试" />
<!-- 单选按钮的组 , 里面包含的是三个单选按钮 , 进行选择的测试 -->
<RadioGroup
android:id="@+id/group"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/radioRed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="红色" />
<RadioButton
android:id="@+id/radioGreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="绿色" />
<RadioButton
android:id="@+id/radioBlack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="黑色" />
</RadioGroup>
<!-- 复选框的测试 -->
<!--
一组: CheckBox 能同时的选择多个,每次点击的时候可以选择是否被选中,在UI 中默认的是以矩形的方式显示;
事件:CompoundButton.OnCheckedChangeListener 后部分与按钮 状态控件的事件名称一致,加以不同的前缀进行区别
-->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="请选择您的爱好"
android:textStyle="normal" />
<CheckBox
android:id="@+id/cb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="游泳" />
<CheckBox
android:id="@+id/cb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="散步" />
<CheckBox
android:id="@+id/cb3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="看书" />
<CheckBox
android:id="@+id/cb4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="篮球" />
<!-- 状态开关测试 -->
<!--
控件名称:ToggeButton
属性:设置开/关的时候对应的文本的值:textOn/textOff
-->
<!-- 开关转换器 默认是开 纵向 -->
<ToggleButton
android:id="@+id/toggle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:checked="true"
android:textOff="横向排列"
android:textOn="纵向排列" />
<!-- 使用线性布局结合状态栏的排列 -->
<LinearLayout
android:id="@+id/linears"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="clock1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="clock2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="clock3" />
</LinearLayout>
</LinearLayout>
<!--
时钟测试
AnalogClock 模拟时钟
DigitalClock 数字时钟
-->
<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:background="@drawable/a"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="时钟测试" />
<AnalogClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<!-- 数字时钟 -->
<!--
时钟(AnalogClock和DigitalClock)的功能和用法:
AnalogClock继承了View组件,重写了View的OnDraw方法,它会在View上显示模拟时钟。
DigitalClock本身就继承了TextView,也就是说它本身就是文本框,只是它里面显示的内容是当前时间。
AnalogClock和DigitalClock都会显示当前时间,不同的是;
DigitalClock显示数字时钟,可以显示当前的秒数;
AnalogClock显示模拟时钟,不会显示当前秒数;
-->
<DigitalClock
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
运行结果(自己写代码时没把时钟代码贴上去):