android-RelativeLayout布局

<?xml version="1.0" encoding="utf-8"?>
<!--RelativeLayout 又称相对布局,也是一种比较常用的布局。
它可以通过相对定位的方式让控件出现在布局的任何位置。
在实际开发过程中,建议使用RelativeLayout来进行uI设计,因为使用RelativeLayout可以减少U中的嵌套结构,
在代码维护及运行效率上来说,具备一定的优势。-->

<!--layout_ centerHrizontal 水平居中
layout_ centerVertical 垂直居中
layout_ centerInparent 相对于父控件完全居中
layout_ alignParentBottom 贴紧父控件的下边缘
layout_ alignParentLeft 贴紧父控件的左边缘
layout_ alignParentRight 贴紧父控件的右边缘
layout_ alignParentTop 贴紧父控件的上边缘
layout_ alignWithParentIfMissing 如果对应的兄弟控件找不到的话,就以父控件作为参照物-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >



    <Button
        android:layout_alignParentLeft="true"
        android:id="@+id/button1"
        android:layout_width="200dp"
        android:layout_height="100dp"
        android:background="@color/black"
        android:text="左上角"

        />

    <Button
        android:layout_alignParentRight="true"
        android:id="@+id/button2"
        android:text="右上角"
        android:background="@color/black"
        android:layout_width="200dp"
        android:layout_height="100dp"


        />

    <Button
        android:layout_alignParentBottom="true"
        android:id="@+id/button3"
        android:layout_width="200dp"
        android:layout_height="100dp"
        android:background="@color/black"
        android:text="左下角"

        />

    <Button
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:id="@+id/button4"
        android:text="右下角"
        android:background="@color/black"
        android:layout_width="200dp"
        android:layout_height="100dp"


        />

    <Button
        android:layout_centerInParent="true"
        android:id="@+id/button5"
        android:text="中间"
        android:background="@color/black"
        android:layout_width="200dp"
        android:layout_height="100dp"


        />


</RelativeLayout>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

76博ding

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

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

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

打赏作者

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

抵扣说明:

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

余额充值