Absolute佈局:
組件的位置可以準確的指定在屏幕的x/y座標位置
雖然可以精確的去規定座標,但是不建議使用。因爲不同的設備 不同的分辨率的手機移動設備上不能很好的顯示應有的效果
<AbsoluteLayout 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"
android:orientation="vertical"
>
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Button1"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="button2"
/>
</AbsoluteLayout>
運行結果如下:
layout_x和layout_y屬性:可以設置具體的x/y座標
代碼如下:
<AbsoluteLayout 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"
android:orientation="vertical"
>
<Button
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Button1"
android:layout_x="100dp"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="button2"
android:layout_y="100dp"
/>
</AbsoluteLayout>
運行如下: