Android常用控件
Android控件的相同屬性
- 所有控件都有的4個屬性:id、layout_width以及layout_height和android:visibility;
Butoon
- Butoon控件是Android程序開發中最常用的控件之一主要功能是通過單機Button來觸發來完成一系列的事件,然後加上監聽器來實現監聽事件。
以下展示一些常見的屬性。
<Button
android:layout_width="50dp"
android:layout_height="wrap_content"
android:text="點擊開始"
android:id="@+id/bt_ks"
android:background="@color/colorAccent"/>
- ImageButton控件是圖片控件,同Button控件相似都是通過點擊當前控件來觸發一系列事件,加上監聽器來實現監聽事件。
以下展示一些常見的屬性。
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/Im_sc"
android:layout_marginTop="100dp"
android:src="@mipmap/ic_launcher"/>
TextView
- TextView也是 Android 程序開發中最常用的控件之一,主要功能是向用戶展示文本的內容,它是不可編輯的 ,只能通過初始化設置或在程序中修改。
以下展示一些常見的屬性。
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="姓名:"
android:textSize="20dp"
android:id="@+id/tv_name"
/>
EidtView
- EidtView與TextView相似,不過EidtView是可以編輯的,可以和用戶進行 交互。
以下展示一些常見的屬性。
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="請輸入您的名字"
android:textSize="20dp"
/>
ImageView
- ImageView是一個圖片控件,負責顯示圖片,既可以用系統提供的資源文件,也可以用 Drawable 對象,且ImageView和ImageButton, 很多屬性都是相同的。
以下展示一下常見的屬性。
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:id="@+id/Iv_tp"
android:scaleType="fitXY"
/>
CheckBox
- CheckBox是複選按鈕,是一種可以進行多選的按鈕,默認以矩形表示。它有選中或者不選中雙狀態。我們可以先在佈局文件中定義多選按鈕, 然後對每一個多選按鈕進行事件監聽 setOnCheckedChangeListener,通過 isChecked 來判斷 選項是否被選中,做出相應的事件響應。
<CheckBox
android:id="@+id/cb1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="九江"
android:textSize="30sp"
android:textColor="#0000FF"
android:textStyle="normal" />
<CheckBox
android:id="@+id/cb2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="南昌"
android:textSize="30sp"
android:textColor="#0000FF"/>
ProgressBar
- ProgressBar 用於在界面上顯示一個進度條,表示我們的程序正在加載一些數據,運行程序,會看到屏幕中有一個圓形進度條正在旋轉。
以下展示一些常見的屬性。
<ProgressBar
android:id="@+id/pb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/bt_ks" />