安卓学习笔记-布局-RelativeLayout相对布局

最常用属性

代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" //定义一个相对布局 里面的子类默认都是重合在一起的 因为是相对的
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:padding="10dp">
    <View //定义一个控件
        android:id="@+id/view_1" //设置id
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:background="#99cc00"
        />
    <View
        android:id="@+id/view_2"
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:background="#ffcccc"
        android:layout_marginLeft="10dp"
        android:layout_toRightOf="@id/view_1"/> //相对布局的属性,设置当前控件在view_1的右边
    <LinearLayout //定义一个线性布局 是相对布局的子类
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_below="@id/view_1" //设置线性布局在view_1的下面
        android:background="#3399ff"
        android:layout_marginTop="20dp"
        android:orientation="vertical">
        <View
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:background="#ff9966" />
        <RelativeLayout //定义一个相对布局
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:background="#66ff33"
            android:layout_marginTop="20dp"
            android:padding="20dp">
            <View
                android:id="@+id/view_3"
                android:layout_width="100dp"
                android:layout_height="70dp"
                android:background="#ff0000" />
            <View
                android:layout_width="100dp"
                android:layout_height="70dp"
                android:background="#cc9900"
                android:layout_toRightOf="@id/view_3" //设置view在view_3的右边 因为是相对布局的子类
                android:layout_marginLeft="15dp"/>
        </RelativeLayout>
    </LinearLayout>

</RelativeLayout>

 

效果

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值