AbsoluteLayout,顧名思義,就是絕對位置的佈局;也可以叫做坐標佈局,也就是指定元素的絕對位置(或者叫絕對坐標值)。這種佈局簡單直接,直觀性強,但是由於手機屏幕尺寸差別比較大,使用絕對定位的適應性會比較差。
<?xml version = "1.0" encoding = "utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dip">
<TextView android:id="@+id/lable"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="請輸入用戶名:"/>
<EditText android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_x="100dip"
android:layout_y="20dip"/>
<Button android:id="@+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="10dip"
android:layout_y="50dip"
android:text="取消"/>
<Button android:id="@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="60dip"
android:layout_y="50dip"
android:text="確定"/>
</AbsoluteLayout>
效果如下:
如果不指定Layout_x 和Layout_y 那麼默認都為0.回顯示在最左上角。
作者“算法 java swing”