RelativeLayout

RelativeLayout(相对布局)的特点 ;灵活性强,属性复杂

第一类:属性用true或false表示

(1)居中

android:layout_centerHrizontal  若为true,水平居中

android:layout_centerVertical  若为true,垂直居中

 android:layout_centerInparent  若为true, 将该控置于父控件的中央

(2)相对于父控件

android:layout_alignParentBottom 若为true,贴紧父元素的下边缘 (该空间的底部与其父控件的底部对齐)

android:layout_alignParentTop   若为true,贴紧父元素的上边缘 ( 该空间的上部与其父控件的上部对齐)

android:layout_alignParentLeft 若为true,贴紧父元素的左边缘  ( 该空间的左部与其父控件的左部对齐)

android:layout_alignParentRight  若为true,贴紧父元素的右边缘 ( 该空间的右部与其父控件的右部对齐)

android:layout_alignWithParentIfMissing 如果对应的兄弟元素找不 到的话就以父元素做参照物

 

第二类:属性值必须为 id 的引用名"@id/id-name"

android:layout_below 将该控件的底部置于给定的ID之下

android:layout_above  将该控件的底部置于给定的ID之上

android:layout_toLeftOf 将该控件的右边缘与给定ID的空间的左边对齐

android:layout_toRightOf 将该控件的左边缘与给定ID的空间的右边对齐

android:layout_alignTop 本控件的上边缘和某控件的的上边缘对齐

 android:layout_alignBottom 本控件的下边缘和某控件的的下边缘对齐

android:layout_alignLeft 本控件的左边缘和某控件的的左边缘对

android:layout_alignRight 本控件的右边缘和某控件的的右边缘对齐

android:layout_alignBaseline本控件的Baseline和某控件的的Baseline对齐

 

第三类:属性值为具体的像素值,如 30dip,40px

android:layout_marginBottom 离某元素底边缘的距离

android:layout_marginLeft 离某元素左边缘的距离

 android:layout_marginRight 离某元素右边缘的距离

 android:layout_marginTop 离某元素上边缘的距离

 

示例;

<?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="fill_parent">
 <TextView
        android:id="@+id/label"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="inputname:"/>
    <EditText
        android:id="@+id/entry"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/label" />
     <Button
        android:id="@+id/ok"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/entry"
        android:layout_alignParentRight="true" 
        android:text="Cancel" />
      <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/ok"
        android:layout_alignTop="@id/ok" 
        android:text="OK"
        android:textColor="#FF0099" />
</RelativeLayout>

 

效果图


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值