Android:UI設計 常用控制元件
TextView
<TextView android:id="@+id/first_txetview" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:textSize="24sp" android:textColor="#00ff00" android:text="This is first TextView!" />
android:layout_width和android:layout_height 指定控制元件的寬度和高度,可選值有三個:match_parent 、fill_parent 、wrap_content 。match_parent 和fill_parent 相似,以父佈局大小決定控制元件大小;wrap_content 以控制元件內容決定控制元件大小。
android:gravity指定文字對齊方式,可選值top、bottom 、right 、left 、center 等,可以用 “| ” 同時指定多個值。
android:textSize和android:textColor 指定文字大小和顏色。
Button
<Button android:id="@+id/first_button" android:layout_width="match_parent" android:layout_height="wrap_content" android:textAllCaps="false" android:text="This is first Button!" />
android:textAllCaps="false"禁用屬性,不對英文字母進行大寫轉換。
EditText
<EditText android:id="@+id/editText" android:layout_width="0dp" android:layout_height="wrap_content" android:hint="Please input something" android:maxLines="2" />
android:hint指定一段提示性文字,當在輸入框輸入內容時,這段文字消失。
android:maxLines指定最大顯示行數,超過後文字會向上滑動。
其他一些控制元件:
android:src給ImageView 指定一張圖片,用於顯示。