原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://webabcd.blog.51cto.com/1787395/342055
系出名门Android(5) – 控件(View)之TextView, Button, ImageButton, ImageView, CheckBox, RadioButton, AnalogClock, DigitalClock
作者:webabcd
介绍
在 Android 中使用各种控件(View)
- TextView - 文本显示控件
- Button - 按钮控件
- ImageButton - 图片按钮控件
- ImageView - 图片显示控件
- CheckBox - 复选框控件
- RadioButton - 单选框控件
- AnalogClock - 钟表(带表盘的那种)控件
- DigitalClock - 电子表控件
1 2 3 4 5 6 7 8 9 10 11 12 | <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <!-- TextView - 文本显示控件 --> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/textView" /> </LinearLayout> |
_TextView.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/textView" /> <!-- Button - 按钮控件 --> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content"> </Button> </LinearLayout> |
_Button.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
3、ImageButton 的 Demo
imagebutton.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/textView" /> <!-- ImageButton - 图片按钮控件 --> <ImageButton android:id="@+id/imageButton" android:layout_width="wrap_content" android:layout_height="wrap_content"> </ImageButton> </LinearLayout> |
_ImageButton.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
4、ImageView 的 Demo
imageview.xml
1 2 3 4 5 6 7 8 9 10 11 12 | <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <!-- ImageView - 图片显示控件 --> <ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView> </LinearLayout> |
_ImageView.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/textView" /> <!-- CheckBox - 复选框控件 --> <CheckBox android:text="CheckBox01" android:id="@+id/chk1" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox> <CheckBox android:text="CheckBox02" android:id="@+id/chk2" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox> <CheckBox android:text="CheckBox03" android:id="@+id/chk3" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox> </LinearLayout> |
_CheckBox.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
6、RadioButton 的 Demo
radiobutton.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/textView" /> <!-- RadioButton - 单选框控件 RadioGroup - 对其内的单选框控件做分组 checkedButton - 指定组内被选中的单选框的 ID --> <RadioGroup android:id="@+id/radioGroup" android:layout_width="fill_parent" android:layout_height="fill_parent" android:checkedButton="@+id/rad3" android:orientation="horizontal" android:gravity="center_vertical|center_horizontal"> <RadioButton android:text="rad1" android:id="@+id/rad1" android:layout_width="wrap_content" android:layout_height="wrap_content"></RadioButton> <RadioButton android:text="rad2" android:id="@+id/rad2" android:layout_width="wrap_content" android:layout_height="wrap_content"></RadioButton> <RadioButton android:text="rad3" android:id="@+id/rad3" android:layout_width="wrap_content" android:layout_height="wrap_content"></RadioButton> </RadioGroup> </LinearLayout> |
_RadioButton.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
7、AnalogClock 的 Demo
analogclock.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 | <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <!-- AnalogClock - 钟表(带表盘的那种)控件 --> <AnalogClock android:id="@+id/analogClock" android:layout_width="wrap_content" android:layout_height="wrap_content"> </AnalogClock> </LinearLayout> |
_AnalogClock.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |
8、DigitalClock 的 Demo
digitalclock.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 | <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <!-- DigitalClock - 电子表控件 --> <DigitalClock android:id="@+id/digitalClock" android:layout_width="wrap_content" android:layout_height="wrap_content"> </DigitalClock> </LinearLayout> |
_DigitalClock.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |
OK
本文出自 “webabcd” 博客,请务必保留此出处http://webabcd.blog.51cto.com/1787395/342055
转载地址:http://disanji.net/2010/12/26/famous-android-5-view-textview-button-imagebutton-imageview-checkbox/