Android基础(四) 常用控件
一、瞎聊
Android常用的控件分类:
- 基本控件 - TextView, EditText, Button views
- 选取控件 - TimePicker, DatePicker
- 列表控件 - ListView, Spinner
- 显示控件 - Gallery , ImageSwitcher
- 菜单 -
- 其他 - AnalogClock, DigitalClock views
二、实例
该实例显示如下控件:Button,ImageButton,EditText,CheckBox ,RadioButton,RadioGroup ,ToggleButton .
- CheckBox - Button的特例,有选中和未选中两种状态。
<CheckBox android:id="@+id/chkAutosave" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Autosave" />
- RadioButton 和 RadioGroup -RadioButton有两种状态(选中和未选中),点击选中后如果再起点击也不会消除选中状态。RadioGroup 是多个RadioButton的集合,在该集合中只能有一个RadioButton被选中。
<RadioGroup android:id="@+id/rdbGp1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <RadioButton android:id="@+id/rdb1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Option 1" /> <RadioButton android:id="@+id/rdb2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Option 2" /> </RadioGroup>
- ToggleButton -Button的特例,可以通过指示来表明选中和未选中状态。
<ToggleButton android:id="@+id/toggle1" android:layout_width="wrap_content" android:layout_height="wrap_content" />
【效果图】
【代码要点】
<?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" > <Button android:id="@+id/btnSave" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Save" /> <Button android:id="@+id/btnOpen" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Open" /> <ImageButton android:id="@+id/btnImg1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/icon" /> <EditText android:id="@+id/txtName" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <CheckBox android:id="@+id/chkAutosave" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Autosave" /> <CheckBox android:id="@+id/star" style="?android:attr/starStyle" mce_style="?android:attr/starStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <RadioGroup android:id="@+id/rdbGp1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <RadioButton android:id="@+id/rdb1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Option 1" /> <RadioButton android:id="@+id/rdb2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Option 2" /> </RadioGroup> <ToggleButton android:id="@+id/toggle1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>
更多相关文章
- Android(安卓)html+动态添加控件,实现textview最后一行的显示效果
- Android之AsyncTask源码分析(第五篇:execute方法只能执行一次的原
- Android标题栏和状态栏显示与否的设置&&& Button或者ImageButton
- Android(安卓)监听网络状态方法详解
- Android(安卓)基础回顾1
- Android-REC制作[从入门到精通]
- Android(安卓)CollapsingToolbarLayout控件
- 关于android中获取横竖瓶状态
- Android(安卓)中使用自定义字体的方法