android中的單選和多選框


先展示一下效果圖

大致代碼如下:

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="fill_parent"
 4     android:layout_height="fill_parent" >
 5 
 6     <TableRow
 7         android:id="@+id/tableRow1"
 8         android:layout_width="wrap_content"
 9         android:layout_height="wrap_content" >
10 
11         <TextView
12             android:id="@+id/textView1"
13             android:layout_width="wrap_content"
14             android:layout_height="wrap_content"
15             android:text="性別:"
16             android:textSize="11pt" />
17 
18         <RadioGroup
19             android:layout_gravity="center_horizontal"
20             android:orientation="horizontal" >
21 
22             <RadioButton
23                 android:id="@+id/radioButton1"
24                 android:layout_width="wrap_content"
25                 android:layout_height="wrap_content"
26                 android:text="男" />
27 
28             <RadioButton
29                 android:id="@+id/radioButton2"
30                 android:layout_width="wrap_content"
31                 android:layout_height="wrap_content"
32                 android:text="女" />
33         </RadioGroup>
34     </TableRow>
35 
36     <TableRow
37         android:id="@+id/tableRow2"
38         android:layout_width="wrap_content"
39         android:layout_height="wrap_content" >
40 
41         <TextView
42             android:id="@+id/textView2"
43             android:layout_width="wrap_content"
44             android:layout_height="wrap_content"
45             android:text="喜歡的顏色:" />
46 
47         <LinearLayout
48             android:layout_width="wrap_content"
49             android:layout_height="wrap_content"
50             android:orientation="vertical" >
51 
52             <CheckBox
53                 android:id="@+id/checkBox2"
54                 android:layout_width="wrap_content"
55                 android:layout_height="wrap_content"
56                 android:text="紅色" />
57 
58             <CheckBox
59                 android:id="@+id/checkBox3"
60                 android:layout_width="wrap_content"
61                 android:layout_height="wrap_content"
62                 android:text="綠色" />
63 
64             <CheckBox
65                 android:id="@+id/checkBox1"
66                 android:layout_width="wrap_content"
67                 android:layout_height="wrap_content"
68                 android:text="藍色" />
69         </LinearLayout>
70     </TableRow>
71 
72 </TableLayout>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM