本章节翻译自《Beginning-Android-4-Application-Development》,如有翻译不当的地方,敬请指出。
原书购买地址http://www.amazon.com/Beginning-Android-4-Application-Development/dp/1118199545/使用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>
但当activity被绘制在一个高分辨率的屏幕上时,AbsoluteLayout就会出现某些问题。
下图是,在使用同样代码的前提下,高分辨率屏幕上显示出来的效果。