在使用android的介面開發工具droiddraw的時候,你會發現,它的預設布局就是絕對布局,也就是用座標來指定每一個控制項的位置,這樣的方法在直接拖控制項的時候顯的比較方便,但是不利於程式的推廣和後期的調整,所以還是建議不使用絕對布局。下面的這個程式是用絕對布局做的一個登入介面,很簡單,就只把xml檔案貼出來了。
<?xml version="1.0" encoding="utf-8"?><AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><!-- 定義一個文字框,使用絕對位置 --><TextView android:layout_x="20dip"android:layout_y="20dip"android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="使用者名稱:"/><!-- 定義一個文本編輯框,使用絕對位置 --><EditText android:layout_x="80dip"android:layout_y="15dip"android:layout_width="wrap_content" android:width="200px" android:layout_height="wrap_content" /><!-- 定義一個文字框,使用絕對位置 --><TextView android:layout_x="20dip"android:layout_y="80dip"android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="密 碼:"/><!-- 定義一個文本編輯框,使用絕對位置 --><EditText android:layout_x="80dip"android:layout_y="75dip"android:layout_width="wrap_content" android:width="200px" android:layout_height="wrap_content" android:password="true"/><!-- 定義一個按鈕,使用絕對位置 --><Button android:layout_x="130dip"android:layout_y="135dip"android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="登 錄"/></AbsoluteLayout>