android 相对布局

这个布局类型常用的属性有点多
android:layout_above 将该控件的底部置于给定ID的控件之上;

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

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

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

android:layout_alignBaseline 将该控件的baseline与给定ID的baseline对齐;

android:layout_alignTop 将该控件的顶部边缘与给定ID的顶部边缘对齐;

android:layout_alignBottom 将该控件的底部边缘与给定ID的底部边缘对齐;

android:layout_alignLeft 将该控件的左边缘与给定ID的左边缘对齐;

android:layout_alignRight 将该控件的右边缘与给定ID的右边缘对齐;

// 相对于父组件

android:layout_alignParentTop 如果为true,将该控件的顶部与其父控件的顶部对齐;

android:layout_alignParentBottom 如果为true,将该控件的底部与其父控件的底部对齐;

android:layout_alignParentLeft 如果为true,将该控件的左部与其父控件的左部对齐;

android:layout_alignParentRight 如果为true,将该控件的右部与其父控件的右部对齐;

// 居中

android:layout_centerHorizontal 如果为true,将该控件的置于水平居中;

android:layout_centerVertical 如果为true,将该控件的置于垂直居中;

android:layout_centerInParent 如果为true,将该控件的置于父控件的中央;

// 指定移动像素

android:layout_marginTop 上偏移的值;

android:layout_marginBottom 下偏移的值;

android:layout_marginLeft   左偏移的值;

android:layout_marginRight   右偏移的值;

看看效果吧,因为属性太多所以就没有一个个的区使用了,只用了个别做代表

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:text="aaa"
        android:background="#ff0000"
        android:textSize="20sp"
        android:gravity="center"
        />
     <TextView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:text="bbb"
        android:background="#faffae00"
        android:textSize="20sp"
        android:gravity="center"
         android:layout_centerHorizontal="true"
        />
    <TextView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:text="ccc"
        android:background="#faffee00"
        android:textSize="20sp"
        android:gravity="center"
         android:layout_alignParentRight="true"
        />
    <TextView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:text="ddd"
        android:background="#fa0015ff"
        android:textSize="20sp"
        android:gravity="center"
        android:layout_centerInParent="true"
        android:layout_margin="10dp"
        android:id="@+id/TV_main_blue"
        />
    <TextView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:text="eee"
        android:background="#fa2c2c2a"
        android:textSize="20sp"
        android:gravity="center"
        android:layout_toLeftOf="@id/TV_main_blue"
        android:layout_centerVertical="true"
        />
     <TextView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:text="eee"
        android:background="#faff00b2"
        android:textSize="20sp"
        android:gravity="center"
        android:layout_toRightOf="@id/TV_main_blue"
        android:layout_alignBottom="@id/TV_main_blue"
        />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:text="eee"
        android:background="#fa05f6ea"
        android:gravity="center"
        android:layout_alignParentBottom="true"
        />


</RelativeLayout>

效果:

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AprilCos

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值