Android笔记(十五) Android中的基本组件——单选框和复选框
2015-08-16 15:42
495 查看
单选框和多选框通常用来在设置用户个人资料时候,选择性别、爱好等,不需要用户直接输入,直接在备选选项中选择,简单方便。
直接看代码:
运行结果:
直接看代码:
<?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" > <TableRow> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="性别" android:textSize="16pt" /> <!-- 定义一组单选按钮 --> <RadioGroup android:orientation="horizontal" android:layout_gravity="center_horizontal" > <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="男" android:textSize="16pt" android:checked="true"/> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="女" android:textSize="16pt"/> </RadioGroup> </TableRow> <TableRow> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="爱好" android:textSize="16pt" /> <!-- 定义一个垂直的线性布局 --> <LinearLayout android:layout_gravity="center_horizontal" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" > <!-- 定义三个复选框 --> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="唱歌" android:textSize="16pt" android:checked="true"/> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="16pt" android:text="看书"/> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="16pt" android:text="购物"/> </LinearLayout> </TableRow> </TableLayout>
运行结果:
![](http://images0.cnblogs.com/blog2015/500720/201508/161541537075003.jpg)
相关文章推荐
- (4.1.34)Android侧滑菜单DrawerLayout的使用
- 断其一指------Handler消息传递机制
- Android开源项目分享
- android判断字符中是否包含表情符
- android截图
- Android(java)学习笔记165:Android的Junit调试
- android图片操作
- android初学者的探索之路(Android音乐播放器)
- 两分钟彻底让你明白Android中onInterceptTouchEvent与onTouchEvent(图文)!
- Android中Toast的用法简介
- Android三级联动筛选菜单
- Android实现计时与倒计时方法
- Android中类的设计遵循的原则
- Android实现天气预报温度/气温折线趋势图
- android 控件中layout_width,layout_height与onMeasure(int widthMeasureSpec, int heightMeasureSpec)
- 下拉刷新,在 ActionBar 上显示效果图
- Android的事件处理之监听与回调
- 布局动画 属性初始 android:animateLayoutChanges
- Android:EditText中切换密码的显示与隐藏
- android 5.1 源码编译adb