当前位置:
首页 >
Android组件的使用:RadioButton
发布时间:2024/1/17
51
豆豆
生活随笔
收集整理的这篇文章主要介绍了
Android组件的使用:RadioButton
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
新建一个Android项目basiccomponent2
1、新建一个布局文件radiobutton_layout.xml,代码如下: |
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout --> 定义线性布局管理器 3 xmlns:android="http://schemas.android.com/apk/res/android" -->引用命名空间 4 android:layout_width="match_parent" -->设置父容器的宽度为屏幕宽度 5 android:layout_height="match_parent" -->设置父容器的高度为屏幕高度 6 android:orientation="vertical" > -->设置父容器中组件排列方式为垂直 7 8 <!-- RadioButton组件必须包裹在RadioGroup组件中 --> 9 <RadioGroup -->定义RadioGroup容器组件 10 android:id="@+id/rg_sex" -->设置容器id 11 android:layout_width="match_parent" -->设置容器宽度为父容器宽度 12 android:layout_height="wrap_content" -->设置容器高度为包裹内容高度 13 android:orientation="horizontal"> -->设置容器中组件排列方式为水平
14 <!-- 设置RadioButton组件 --> 15 <RadioButton -->定义RadioButton组件 16 android:id="@+id/rb_sex_male" -->设置组件id 17 android:layout_width="wrap_content" -->设置组件宽度为包裹内容宽度 18 android:layout_height="wrap_content" -->设置组件高度为包裹内容高度 19 android:text="@string/rb_sex_male_txt"/> -->设置组件默认文本,从string.xml中读取id为rb_sex_male_txt的内容
20 <!-- 设置RadioButton组件 --> 21 <RadioButton 22 android:id="@+id/rb_sex_female" -->设置组件id 23 android:layout_width="wrap_content" -->设置组件宽度为包裹内容宽度 24 android:layout_height="wrap_content" -->设置组件高度为包裹内容高度 25 android:text="@string/rb_sex_female_txt"/> -->设置组件默认文本,从string.xml中读取id为rb_sex_female_txt的内容 27 </RadioGroup> 28 </LinearLayout>
2、在string.xml中定义两个文本,代码如下: |
3、新建一个RadioButtonActivity类继承Activity类,并覆写相应方法: |
4、把RadioButtonActivity配置到AndroidManifest.xml文件中,并设置程序入口,代码如下 |
2013-07-19
转载于:https://www.cnblogs.com/zhengweicong/p/3201715.html
创作挑战赛新人创作奖励来咯,坚持创作打卡瓜分现金大奖总结
以上是生活随笔为你收集整理的Android组件的使用:RadioButton的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: android如何获取默认的桌面程序
- 下一篇: Android-04:线程的使用