Android学习笔记(二)——RelativeLayout

Android小白,初次学习,笔记自用,敬请指正~😛
有帮助记得一键三连呀(点赞收藏关注)😁

一,最常用属性:

1,相对于给定ID控件
android:layout_above="@id/id标识(id名)"  将该控件置于给定id的控件之上;
android:layout_below="@id/id标识(id名)"  与上相反;

android:layout_toLeftOf="@id/id标识(id名)"    将该控件置于给定id的控件左边(该控件的右边缘与给定id的控件左边缘对齐);
android:layout_toRightOf="@id/id标识(id名)"   与上相反;

android:layout_alignTop="@id/id标识(id名)"        将该控件的顶部边缘与给定id的顶部边缘对齐;
android:layout_alignBottom="@id/id标识(id名)"     底部边缘对齐;
android:layout_alignLeft="@id/id标识(id名)"       左边缘对齐;
android:layout_alignRight="@id/id标识(id名)"      右边缘对齐;


2,相对于父组件
android:layout_alignParentTop="true|false"      如果为true,将该控件的顶部与其父控件的顶部对齐;
android:layout_alignParentBottom="true|false"   底部对齐;
android:layout_alignParentLeft="true|false"     左部对齐;
android:layout_alignParentRight="true|false"    右部对齐;

3,居中操作
android:layout_centerHorizontal="true|false"   如果为true,将该控件的置于水平居中;
android:layout_centerVertical="true|false"     垂直居中;
android:layout_centerInParent="true|false"     置于父控件的中央;

二,实例演示:

<?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">

    <View
        android:id="@+id/view1"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:background="#000000"/>
    <View
        android:id="@+id/view2"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="#FF0033"
        android:layout_alignParentRight="true"
        android:layout_alignBottom="@id/view1"/>
    <View
        android:id="@+id/view3"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:background="#FF6633"
        android:layout_centerInParent="true"/>

    <LinearLayout
        android:id="@+id/ll_1"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_below="@+id/view3"
        android:background="#0077DD"
        android:padding="15dp"
        android:layout_marginTop="40dp">

        <View
            android:layout_width="100dp"
            android:layout_height="match_parent"
            android:background="#FF0033"/>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#000000"
            android:padding="15dp">

            <View
                android:id="@+id/view4"
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:background="#FF9900"/>
            <View
                android:id="@+id/view5"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_alignParentRight="true"
                android:layout_centerInParent="true"
                android:background="#AA6699"/>

        </RelativeLayout>
    </LinearLayout>

</RelativeLayout>

三,效果图:

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值