android的UI控件的用法和注意点(1)
2015-02-06 10:56
141 查看
1、Button
1.1、Button和ImageButton
这两个控件的区别在于
1)Button按钮生成的按钮上显示文字,而ImageButton上则只显示图片
2)Button只能添加一种背景(通常情况下),而ImageButton只能显示图片,而不能添加文字
为了开发能够随按键状态改变的Button,我们需要开发出Drawable进行状态控制
1)ImageButton 随按键状态改变
<ImageButton
android:layout_width="wrap_comtent"
android:layout_height="wrap_content"
android:src="@drawable/button_state"/>
Button_state.xml
<?xml version="1.0" encoding="UTF-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed ="true"
android:drawable=”@drawable/red“/>
<item android:state_pressed="false"
android:drawable="@drawable/black"/>
</selector>
2)Button 随按钮状态改变,且显示文字
<Button
android:layout_width="wrap_comtent"
android:layout_height="wrap_content"
android:src="@drawable/button_state"
android:text="带文字改变背景状态的按钮"/>
2.2、RadioButton和CheckBox
这两个控件在于RadioButton是每次选择一个值,所以一般封装在RadioGroup中 ,而CheckBox则不需要(多选的优点)所以每个选项都有一个ID
eg-RadioButton:
1)RadioButton
<RadioGroup
android:id="@id/RadioGroup"
android:orientation="horizontal"
android:layout_gravity="center_horizontal">
<RadioButton
android:id="@id/RadioButton1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="男"/>
<RadioButton
android:id="@id/RadioButton2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="女"/>
</RadioGroup>
eg-CheckBox:
1)布局
<checkBox
android:id="@id/hobby"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="球"/>
<checkBox
android:id="@id/hobby"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="田径"/>
<checkBox
android:id="@id/hobby"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="滑翔"/>
1.1、Button和ImageButton
这两个控件的区别在于
1)Button按钮生成的按钮上显示文字,而ImageButton上则只显示图片
2)Button只能添加一种背景(通常情况下),而ImageButton只能显示图片,而不能添加文字
为了开发能够随按键状态改变的Button,我们需要开发出Drawable进行状态控制
1)ImageButton 随按键状态改变
<ImageButton
android:layout_width="wrap_comtent"
android:layout_height="wrap_content"
android:src="@drawable/button_state"/>
Button_state.xml
<?xml version="1.0" encoding="UTF-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed ="true"
android:drawable=”@drawable/red“/>
<item android:state_pressed="false"
android:drawable="@drawable/black"/>
</selector>
2)Button 随按钮状态改变,且显示文字
<Button
android:layout_width="wrap_comtent"
android:layout_height="wrap_content"
android:src="@drawable/button_state"
android:text="带文字改变背景状态的按钮"/>
2.2、RadioButton和CheckBox
这两个控件在于RadioButton是每次选择一个值,所以一般封装在RadioGroup中 ,而CheckBox则不需要(多选的优点)所以每个选项都有一个ID
eg-RadioButton:
1)RadioButton
<RadioGroup
android:id="@id/RadioGroup"
android:orientation="horizontal"
android:layout_gravity="center_horizontal">
<RadioButton
android:id="@id/RadioButton1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="男"/>
<RadioButton
android:id="@id/RadioButton2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="女"/>
</RadioGroup>
eg-CheckBox:
1)布局
<checkBox
android:id="@id/hobby"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="球"/>
<checkBox
android:id="@id/hobby"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="田径"/>
<checkBox
android:id="@id/hobby"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="滑翔"/>
相关文章推荐
- Android UI控件----ExpandableListView的基本用法
- Android UI开发专题(四) View自绘控件
- Android UI开发专题(四) View自绘控件
- Android精简小笔记(9):Spinner的用法(下拉选项控件):
- Android UI开发专题(四) View自绘控件
- android UI进阶之自定义组合控件
- Android UI,界面辅助设置工具,可随意拖动控件,比google官方提供的方便
- Android UI控件自动提示控件(AutoCompleteTextView)
- Android UI开发 View自绘控件
- android UI进阶之自定义组合控件
- Android UI 优化 [ 类别:Layout ] #3 merge用法 -android
- androidUI第四部分--1.4.1ListView用法—利用ArrayAdapter生成ListView
- Android UI开发专题(四) View自绘控件
- androidUI第六部分---其他常用控件举例
- Android精简小笔记(1):SlidingDrawer控件(抽屉)的用法
- Android UI开发专题(四) View自绘控件
- androidUI第五部分--1.5.2Toast用法
- android 关于线程更新UI控件,包括gridview,textview,imageview等
- android UI进阶之自定义组合控件 推荐
- android UI进阶之自定义组合控件