18.9.11-相对布局

相对布局

常用属性

  1. toLeftOf: 置于左侧
  2. alignBottom: 底部对齐
  3. alignParentBottom: 父空间底部对齐
  4. below: 置于下侧

Demo

<?xml version="1.0" encoding="utf-8"?>
<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">

    <View
        android:id="@+id/veiw_1"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="#000" />
    <View
        android:id="@+id/veiw_2"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="#FF00"
        android:layout_toRightOf="@id/veiw_1"
        android:layout_below="@id/veiw_1"/>
    <View
        android:id="@+id/veiw_3"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="#44A3BB"
        android:layout_below="@id/veiw_1"/>

    <LinearLayout
        android:id="@+id/ll_1"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true"
        android:layout_marginBottom="177dp"
        android:background="#5E79A2"
        android:orientation="horizontal"
        android:padding="15dp">

        <View
            android:id="@+id/view_4"
            android:layout_width="100dp"
            android:layout_height="match_parent"
            android:background="#030303" />

        <RelativeLayout
            android:id="@+id/rl_1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#32CD32"
            android:padding="15dp">

            <View
                android:id="@+id/view_5"
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:background="#D2691E" />
            <View
                android:id="@+id/view_6"
                android:layout_width="100dp"
                android:layout_height="match_parent"
                android:layout_marginLeft="50"
                android:background="#DA70D6"
                android:layout_toRightOf="@id/view_5"/>
        </RelativeLayout>

    </LinearLayout>

</RelativeLayout>
android1.PNG
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容