Android基础#13: Layout经典布局--绝对布局AbsoluteLayout的使用
世间无绝对,真是这样的么?——-箴言——-
内容简介:
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的各种布局需求。
还没有评论,来说两句吧...