世間無絕對,真是這樣的麼?-----箴言-----
内容簡介:
Android提供了AbsoluteLayout,即絕對布局, 即設定控件的絕對位置,控件坐标"從x,y"開始進行排列。
在使用AbsoluteLayout布局方式時,需要指定空間的x,y精确坐标。
舉例如下:
下面是一個簡單的父布局為AbsoluteLayout的xml檔案:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#CCCCCC"
>
<Button
android:background="#11EE11"
android:layout_x="48px"
android:layout_y="48px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按鈕1"></Button>
<Button
android:background="#1111DD"
android:layout_x="300px"
android:layout_y="100px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按鈕2"></Button>
<Button
android:background="#CC2222"
android:layout_x="200px"
android:layout_y="300px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按鈕3"></Button>
</AbsoluteLayout>
效果如下:
可見,在AbsoluteLayout中,按鈕被固定在絕對坐标的位置上。
注:事實上,不推薦使用該布局。因為在實際應用中,LinearLayout,FrameLayout,FragmeLayout幾乎可以完全滿足UI的各種布局需求。