Android组件的使用:RadioButton
生活随笔
收集整理的這篇文章主要介紹了
Android组件的使用:RadioButton
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
?新建一個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" -->設(shè)置父容器的寬度為屏幕寬度 5 android:layout_height="match_parent" -->設(shè)置父容器的高度為屏幕高度 6 android:orientation="vertical" > -->設(shè)置父容器中組件排列方式為垂直 7 8 <!-- RadioButton組件必須包裹在RadioGroup組件中 --> 9 <RadioGroup -->定義RadioGroup容器組件 10 android:id="@+id/rg_sex" -->設(shè)置容器id 11 android:layout_width="match_parent" -->設(shè)置容器寬度為父容器寬度 12 android:layout_height="wrap_content" -->設(shè)置容器高度為包裹內(nèi)容高度 13 android:orientation="horizontal"> -->設(shè)置容器中組件排列方式為水平14 <!-- 設(shè)置RadioButton組件 --> 15 <RadioButton -->定義RadioButton組件 16 android:id="@+id/rb_sex_male" -->設(shè)置組件id 17 android:layout_width="wrap_content" -->設(shè)置組件寬度為包裹內(nèi)容寬度 18 android:layout_height="wrap_content" -->設(shè)置組件高度為包裹內(nèi)容高度 19 android:text="@string/rb_sex_male_txt"/> -->設(shè)置組件默認文本,從string.xml中讀取id為rb_sex_male_txt的內(nèi)容
20 <!-- 設(shè)置RadioButton組件 --> 21 <RadioButton 22 android:id="@+id/rb_sex_female" -->設(shè)置組件id 23 android:layout_width="wrap_content" -->設(shè)置組件寬度為包裹內(nèi)容寬度 24 android:layout_height="wrap_content" -->設(shè)置組件高度為包裹內(nèi)容高度 25 android:text="@string/rb_sex_female_txt"/> -->設(shè)置組件默認文本,從string.xml中讀取id為rb_sex_female_txt的內(nèi)容 27 </RadioGroup> 28 </LinearLayout>
2、在string.xml中定義兩個文本,代碼如下: |
3、新建一個RadioButtonActivity類繼承Activity類,并覆寫相應(yīng)方法: |
4、把RadioButtonActivity配置到AndroidManifest.xml文件中,并設(shè)置程序入口,代碼如下 |
?
2013-07-19
轉(zhuǎn)載于:https://www.cnblogs.com/zhengweicong/p/3201715.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的Android组件的使用:RadioButton的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android如何获取默认的桌面程序
- 下一篇: Bitmap Index