使用AbsoluteLayout,可以指定它其中的子View的確切位置。觀察如下main.xml中的代碼:
- <?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="fill_parent" >
- <Button
- android:layout_width="188dp"
- android:layout_height="wrap_content"
- android:layout_x="126px"
- android:layout_y="361px"
- android:text="Button" />
- <Button
- android:layout_width="113dp"
- android:layout_height="wrap_content"
- android:layout_x="12px"
- android:layout_y="361px"
- android:text="Button" />
- </AbsoluteLayout>
下面是效果圖,使用瞭android:layout_x和android_y屬性,把兩個Button放置在瞭確切的位置上。
但當activity被繪制在一個高分辨率的屏幕上時,AbsoluteLayout就會出現某些問題。
下圖是,在使用同樣代碼的前提下,高分辨率屏幕上顯示出來的效果。
出於這個原因,從Android1.5開始,Google官方已經不推薦使用這個佈局瞭,盡管它現在還是可以使用的。在創建UI的時候,應該避免使用AbsoluteLayout這個佈局,因為,Android並不確保會在將來的版本中還繼續支持它。
摘自 manoel的專欄