Android開發中XML布局的常用屬性說明,android開發xml布局
<!-- 常用屬性說明: android:id="@+id/button" 為控制項指定Id android:text="NNNNNNNNNN" 指定控制項的顯示文本 android:textSize="12pt" 讓控制項中的文字顯示尺寸 android:singleLine="true" 讓控制項中顯示的文本在一行顯示完,顯示不了的自動省略 android:gravity="left" 讓控制項中的內容靠左顯示 android:padding="16dp" 讓控制項中的文本距控制項外邊框的填充尺寸,可以像CSS裡的padding_left... android:background="#ff0000" 控制項中的背景顏色 android:width="1060dip" 指定控制項的寬度,好像不起作用了 android:height="200dip" 指定控制項的高度,好像不起作用了 android:layout_width="200dp" 控制項布局寬度,如果是fill_parent 表示水平填充滿父控制項 android:layout_height="wrap_content" 填充高度;fill_parent表示填滿父控制項,最好不要。 android:layout_weight="1" 表示與同級控制項的布局權重,如果就兩個都是1那就是一人一半,數字大的佔用的空間多 -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_alignParentStart="true"> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="NNN" android:width="160dp" android:height="200dp" android:background="#ff0000" android:textSize="12pt" android:gravity="right" android:padding="16dp" android:singleLine="true" android:layout_weight="1" android:id="@+id/button" /> <!-- android:singleLine="true" 表示單行顯示,顯示不完的省略 --> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="New Button" android:id="@+id/button4" android:layout_gravity="right" android:layout_weight="2" /> </LinearLayout></RelativeLayout>