今天我們來和大家一起認(rèn)識Android幾個(gè)最基本的控件蠢古,分別是顯示文本的TextView、用于輸入額EditText别凹、用于點(diǎn)擊的Button和顯示圖像的ImageView草讶,那為了更好地呈現(xiàn)這幾個(gè)控件了,我們先認(rèn)識一下Android的一種最簡單的布局——線性布局
一炉菲、線性布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:background="#0f0"
>
</LinearLayout>
二堕战、文本控件TextView
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="這是用于顯示文字的控件"
/>
三 、輸入控件
<EditText
android:layout_width="match_parent"
android:layout_height="40dp"
android:hint="請輸入文字"
/>
四拍霜、按鈕控件Button
<Button
android:layout_width="match_parent"
android:layout_height="48dp"
android:text="這是個(gè)按鈕"/>
五 圖片控件ImageView
<ImageView
android:id="@+id/iv_g1"
android:layout_width="300dp"
android:layout_height="300dp"
android:background="#888"
>
上面我沒放圖片嘱丢,考慮到各位那邊不一定有那張圖片,你們可以添加自己圖片測試
六祠饺、總結(jié)
Android的控件都繼承于View越驻,View都有一下幾個(gè)常用屬性,也都可以給View設(shè)置點(diǎn)擊事件道偷。
- 控件的寬
android:layout_width="match_parent"
- 控件的高
android:layout_height="40dp"
- 背景顏色
android:background="#ff0000"
- id
android:id="@+id/iv_g1"