Android五大布局之相对布局

一.RelativeLayout(相对布局)重点:

在没有指点位置的情况下,RelativeLayout会默认生成控件的位置是左上角

所以必须需要添加属性android:id="@+id/name"定义控件的名称,其他控件就可以通过@id/name找到它进行相对布局

二.RelativeLayout(相对布局)相关的属性:
在这里插入图片描述

<?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" >
    
    <Button 
        
        android:id="@+id/cbut"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="中间"
        
        />
    
    <Button 
        
        android:id="@+id/tbut"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_above="@id/cbut"    
        android:text="上面"
        
        />
    
    <Button 
        
        android:id="@+id/tlbut"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_above="@id/cbut"
        android:layout_toLeftOf="@id/tbut"     
        android:text="左上"
        
        />
    
    <Button 
        
        android:id="@+id/trbut"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_above="@id/cbut"
        android:layout_toRightOf="@id/tbut"     
        android:text="右上"
        
        />
    
    <Button 
        
        android:id="@+id/bbut"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_below="@id/cbut"   
        android:text="下面"
        
        />
    
    <Button 
        
        android:id="@+id/lbut"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_toLeftOf="@id/cbut"  
        android:text="左面"
        
        />
    
    <Button 
        
        android:id="@+id/rbut"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_toRightOf="@id/cbut"
        android:text="右面"
        
        />

    <Button
        android:id="@+id/blbut"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/bbut"
        android:layout_alignLeft="@+id/lbut"
        android:text="左下" />

    <Button
        android:id="@+id/brbut"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/bbut"
        android:layout_alignLeft="@+id/rbut"
        android:text="右下" />
    
</RelativeLayout>

运行结果如下:
在这里插入图片描述
以上就是我对RelativeLayout(相对布局)理解

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值