視窗的布局是在layout中的.xml檔案中實現的
一般可以使用eclipse的代碼提示功能 Alt+/來顯示後面要加的屬性值
首先看一下線性布局式樣:LinearLayout
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <!-- 視窗的布局,這裡是垂直的,也可以是水平的 --> <!-- android:id ~~~~~~~~~~~~~ 為控制項指定相應的ID,以便訪問控制項 android:text ~~~~~~~~~~~~~ 指定控制項當中顯示的文字,這裡盡量使用string.xml檔案中定義的string android:grivity ~~~~~~~~~~~~~ 指定控制項中顯示的內容在控制項中所處的位置 android:textSize ~~~~~~~~~~~~~ 指定控制項當中字型的大小 android:background ~~~~~~~~~~~~~ 指定控制項中所指定的背景色,用RGB方法 android:layout_width ~~~~~~~~~~~~~ 控制項寬度 android:layout_height ~~~~~~~~~~~~~ 控制項高度 android:padding* ~~~~~~~~~~~~~ 控制項的內邊距 android:sigleLine ~~~~~~~~~~~~~ 如果為真的話,則控制項中的內容在同一行中顯示,顯示不完就用 ...表示 --> <TextView android:id="@+id/firstText" android:text="first Line" android:gravity="center_vertical" android:textSize="18pt" android:background="#aa0000" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingLeft="10dip" android:paddingRight="30dip" android:paddingTop="20dip" android:paddingBottom="10dip" android:layout_weight="1" android:singleLine="true"/> <TextView android:id="@+id/secondText" android:text="second Line" android:gravity="center_vertical" android:textSize="18pt" android:background="#00aa00" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingLeft="10dip" android:paddingRight="30dip" android:paddingTop="20dip" android:paddingBottom="10dip" android:layout_weight="2" android:singleLine="true"/> <Button android:id="@+id/myButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="2" /></LinearLayout>
再來看一下表格版面配置:TableLayout
<?xml version="1.0" encoding="utf-8"?><TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="0" > <!-- 表示通過展開第一列來填滿螢幕 --> <!-- 第一行 --> <TableRow> <!-- 第一行中設定了三列 --> <TextView android:text="@string/row1_column1" android:background="#aa0000" android:padding="3dip" /> <TextView android:text="@string/row1_column2" android:background="#00aa00" android:padding="3dip" /> <TextView android:text="@string/row1_column3" android:background="#0000aa" android:padding="3dip" /> </TableRow> <!-- 第二行 --> <TableRow> <!-- 第二行中設定了兩列 --> <TextView android:text="@string/row2_column1" android:background="#00aa00" android:padding="3dip" /> <TextView android:text="@string/row2_column2" android:background="#0000aa" android:padding="3dip" /> </TableRow></TableLayout>