7.3 RelativeLayout布局详解
发布时间:2022-11-25 16:52:28 361 相关标签: # android
RelativeLayout相对布局, 允许子元素指定他们相对于其它元素或父元素的位置(通过ID 指定)。因此,可以以左右对齐、上下对齐、置于屏幕中央等形式来排列元素。相对布局在实际应用中比较常用。图7-13所示是垂直方向上的应用。
图7-13 RelativeLayout1
RelativeLayout布局文件请参考代码清单7-15,完整代码请参考chapter7_3工程中relativelayout1.xml代码部分(chapter7_3/res/layout/relativelayout1.xml)。
【代码清单7-15】
android:layout_width="match_parent" android:layout_height="wrap_content"
android:padding="10dip">
android:layout_height="wrap_content" android:layout_alignParentTop="true"
android:text="上" android:background="#ff0060" />
android:layout_height="wrap_content" android:layout_alignParentBottom="true"
android:text="下" android:background="#2121f4" />
android:layout_height="wrap_content" android:layout_above="@id/labe2"
android:layout_below="@id/labe1" android:text="中"
android:background="#ffffff" />
图7-14所示是水平方向上的应用。
图7-14 RelativeLayout2
RelativeLayout布局文件请参考代码清单7-16,完整代码请参考chapter7_3工程中relativelayout2.xml代码部分(chapter7_3/res/layout/relativelayout2.xml)。
【代码清单7-16】
android:layout_width="match_parent" android:layout_height="wrap_content"
android:padding="10dip">
android:layout_height="wrap_content" android:text="@string/search" />
android:layout_height="wrap_content" android:layout_below="@id/labe4"
android:background="@android:drawable/editbox_background" />
出自《Android开发案例驱动教程》第七章
文章来源: https://blog.51cto.com/tonyguan/5704192
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报