欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android学习笔记之——UI组件/RelativeLayout(相对布局)

程序员文章站 2023-01-21 21:50:37
RelativeLayout最常用属性android:layout_ toLeftOfandroid:layout_ belowandroid:layout_toRightOfandroid:layout_ alignBottomandroid:layout_ alignParentBottom实例

RelativeLayout

最常用属性
android:layout_ toLeftOf
android:layout_ below
android:layout_toRightOf
android:layout_ alignBottom
android:layout_ alignParentBottom

实例

<?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:layout_width="100dp"
        android:layout_height="100dp"
        android:id="@+id/view_1"
        android:background="#000000"
        ></View>
    <View
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:id="@+id/view_2"
        android:background="#FF0033"
        android:layout_below="@id/view_1"
        ></View>
    <LinearLayout
        android:id="@+id/ll_1"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_below="@id/view_2"
        android:orientation="horizontal"
        android:background="#0066FF"
        android:padding="15dp">
        <View
            android:layout_width="100dp"
            android:layout_height="match_parent"
            android:background="#FF0033">
        </View>
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#000000"
            android:padding="15dp"
            >
            <View
                android:id="@+id/view_3"
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:background="#FF99"></View>
            <View
                android:id="@+id/view_4"
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:background="#FF9900"
                android:layout_toRightOf="@id/view_3"
                android:layout_marginLeft="10dp"></View>
        </RelativeLayout>
    </LinearLayout>
</RelativeLayout>

运行效果:
Android学习笔记之——UI组件/RelativeLayout(相对布局)

本文地址:https://blog.csdn.net/weixin_43561635/article/details/107189292