android开发随笔 RelativeLayout

RelativeLayout 相对布局 此容器内的子元素可以使用彼此之间的相对位置或者和容器间的相对位置来进行定位。不能在RelativeLayout容器本身和他的子元素之间产生循环依赖,如:A要在B下面,B要在A上面,OMG...

布局属性:

          1.android:layout_above将该控件置于给定ID的控件之上 

          2.android:layout_below 将该控件的置于给定 ID 控件之下
          3.android:layout_toLeftOf   将该控件置于给定 ID 的控件之左
          4.android:layout_toRightOf 将该控件置于给定 ID 的控件之右

          5.android:layout_alignBaseline该控件基线对齐给定ID的基线  (如果有A控件TextView和B控件Button  A设置属性.android:layout_alignBaseline指向ID为B的话,那么就意味着A这个 TextView中的文本会水平对齐到 B控件的text的 )
          6.android:layout_alignBottom该控件于给定ID的控件底部对齐
          7.android:layout_alignLeft该控件于给定ID的控件左对齐
          8.android:layout_alignRight该控件于给定ID的控件右对齐
          9.android:layout_alignTop该控件于给定ID的控件顶对齐


         <针对容器的>
         10. android:layout_alignParentLeft 如果为 True ,该控件位于父控件的左部
         11.android:layout_alignParentRight 如果为 True ,该控件位于父控件的右部
         12.android:layout_alignParentTop 如果为 True ,该控件位于父控件的顶部
         13. android:layout_alignParentBottom 如果为 True ,该控件位于父控件的底部

         14.android:layout_centerHorizontal 如果为 True ,该控件将被置于水平方向的中央
         15. android:layout_centerInParent   如为 Ture ,该控件将被置于父控件水平方向和垂直方向
         16.android:layout_centerVertical 如果为 True ,该控件将被置于垂直方向的中央


main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#0000FF"
    android:padding="10px" >

    <TextView
        android:id="@+id/tv1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#FF0000"
        android:text="Type here:" />

    <EditText
        android:id="@+id/et1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/tv1" />

    <Button
        android:id="@+id/btn2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@id/et1"
        android:text="取消" />

    <Button
        android:id="@+id/btn1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/et1"
        android:layout_toLeftOf="@id/btn2"
        android:text="确定" />
    <!-- layout_alignLeft、layout_alignRight......是指和指定ID的控件相对位置 -->

</RelativeLayout>





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值