18.9.11-相对布局

2018-09-11  本文已影响0人  VGSemir

相对布局

常用属性

  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
上一篇 下一篇

猜你喜欢

热点阅读