RelativeLayout

来源:互联网 发布:软件药品库 编辑:程序博客网 时间:2024/06/05 02:07

         说明:感谢若水老师的课件!

RelativeLayout顾名思义,相对布局,在这个容器内部的子元素们可以使用彼此之间的相对位置或者和容器间的相对位置来进行定位。

注意:不能在RelativeLayout容器本身和他的子元素之间产生循环依赖,比如说,不能将RelativeLayout的高设置成为WRAP_CONTENT的时候将子元素的高设置成为 ALIGN_PARENT_BOTTOM。

    • android:layout_above 将该控件置于给定ID的控件之上
    • android:layout_below 将该控件的置于给定ID控件之下
    • android:layout_toLeftOf将该控件置于给定ID的控件之左
    • android:layout_toRightOf 将该控件置于给定ID的控件之右
    • android:layout_alignBaseline 该控件基线对齐给定ID的基线
    • android:layout_alignBottom 该控件于给定ID的控件底部对齐
    • android:layout_alignLeft 该控件于给定ID的控件左对齐
    • android:layout_alignRight 该控件于给定ID的控件右对齐
    • android:layout_alignTop 该控件于给定ID的控件顶对齐
    • android:layout_alignParentLeft 如果为True,该控件位于父控件的左部
    • android:layout_alignParentRight 如果为True,该控件位于父控件的右部
    • android:layout_alignParentTop 如果为True,该控件位于父控件的顶部
    • android:layout_alignParentBottom 如果为True,该控件位于父控件的底部
    • android:layout_centerHorizontal 如果为True,该控件将被置于水平方向的中央
    • android:layout_centerInParent  如为Ture,该控件将被置于父控件水平方向和垂直方向
    • android:layout_centerVertical 如果为True,该控件将被置于垂直方向的中央
相对布局示例:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent" >    <TextView        android:id="@+id/tv01"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:textSize="24sp"        android:text="标题党首"         android:layout_centerHorizontal="true"/>    <EditText        android:id="@+id/et01"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:inputType="phone"        android:drawableLeft="@drawable/ic_launcher"        android:layout_below="@id/tv01" />    <Button        android:id="@+id/btn01"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignParentRight="true"        android:layout_below="@id/et01"        android:text="确认" />    <Button        android:id="@+id/btn02"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_below="@id/et01"        android:layout_toLeftOf="@id/btn01"        android:text="取消" /></RelativeLayout>


0 0
原创粉丝点击