`
fanfanlovey
  • 浏览: 71670 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

Android入门学习七:基本控件学习

阅读更多
TextView
用于向用户显示文字
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/save"/>



Button
按钮控件
<Button android:id="@+id/btnSave"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/save" 
    android:onClick="btnSaved_clicked"/>


ImageButton
按钮控件,可以展示图片
<ImageButton android:id="@+id/btnImg1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_launcher" />

style属性的格式如下:
?[package:][type:]name

EditText
TextView的子视图,用户可以编辑内容,当在EditText中输入文字时候,他的宽度会自动变化
<EditText android:id="@+id/txtName"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" />


CheckBox
具有2个状态的特殊按钮类型:选中或未选中
<CheckBox android:id="@+id/chkAutosave"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Autosave" />



RadioGroup和RadioButton
RadioButton有2种状态:选中未选中
RadioGroup用来把一个或多个RadioButton组合在一起,每次只能有一个RadioButton被选中

<RadioGroup android:id="@+id/rdbGp1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
    <RadioButton android:id="@+id/rdb1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Option 1" />
    <RadioButton android:id="@+id/rdb2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Option 2" />
</RadioGroup>

ToggleButton
用一个灯光 指示器来显示选中/未选中状态
<ToggleButton android:id="@+id/toggle1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />


ProgressBar
提供了一个正在进行的任务的视觉反馈
<ProgressBar android:id="@+id/progressbar"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    style="@android:style/Widget.ProgressBar.Horizontal" />


AutoCompleteTextView
是一种与EditText类似的视图(实际上他是EditText的子类),只不过它还在用户输入时自动显示完成建议的列表
<AutoCompleteTextView android:id="@+id/txtCountries"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

   textView.setThreshold(3); //显示下拉菜单用户必须输入的最小字符个数



TimePicker
可以按24小时或者AM/PM模式选择时间
<TimePicker android:id="@+id/timePicker"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />


DatePicker
选择指定日期
<DatePicker android:id="@+id/datePicker"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />


ListView
在一个垂直滚动列表中显示列表项列表,扩展ListActivy类并且绑定数据源
<ListView 
    android:id="@+id/android:list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />


Spinner
一次显示列表中的一项,点击可以展示所有列表,选中之后隐藏列表,展示选择的数据项
<Spinner
    android:id="@+id/spinner1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawSelectorOnTop="true" />


特殊碎片
  • ListFragment
  • DialogFragment
  • PreferneceFragment


Gallery
是一种固定在中间位置的水平滚动列表显示列表项(如图片),目前已经废弃

ImageSwitcher
图片选择器

GridView
在一个二维的滚动网络中来显示项

AnalogClock
显示一个有2个指针(时针和分针)模拟时钟

DigitalClock
数字的方式显示时钟

WebView
加载网页控件
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics