android_相對佈局常見的幾種佈局形式

<?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"
    tools:context=".SecondActivity">
    <TextView
        android:textColor="#fff"
        android:textSize="30sp"
        android:text="上"
        android:gravity="center"
        android:layout_above="@id/bottom"
        android:background="@color/colorPrimaryDark"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <TextView
        android:id="@+id/bottom"
        android:background="@color/colorAccent"
        android:layout_alignParentBottom="true"
        android:text="下"
        android:textSize="30sp"
        android:textColor="#fff"
        android:gravity="center"
        android:layout_width="match_parent"
        android:layout_height="50dp" />
</RelativeLayout>

<?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"
    tools:context=".SecondActivity">
    <TextView
        android:gravity="center"
        android:text="上"
        android:textSize="30sp"
        android:textColor="#fff"
        android:id="@+id/top"
        android:layout_width="match_parent"
        android:background="@color/colorAccent"
        android:layout_height="50dp" />
    <TextView
        android:gravity="center"
        android:text="下"
        android:textSize="30sp"
        android:textColor="#fff"
        android:layout_below="@id/top"
        android:background="@color/colorPrimaryDark"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</RelativeLayout>

<?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"
    tools:context=".SecondActivity">
    <TextView
        android:gravity="center"
        android:text="上"
        android:textSize="30sp"
        android:textColor="#fff"
        android:id="@+id/top"
        android:layout_width="match_parent"
        android:background="@color/colorAccent"
        android:layout_height="50dp" />
    <TextView
        android:id="@+id/center"
        android:gravity="center"
        android:text="中"
        android:textSize="30sp"
        android:textColor="#fff"
        android:layout_below="@id/top"
        android:layout_above="@+id/bottom"

        android:background="@color/colorPrimaryDark"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <TextView
        android:id="@+id/bottom"
        android:layout_alignParentBottom="true"
        android:gravity="center"
        android:text="下"
        android:textSize="30sp"
        android:textColor="#fff"
        android:background="@color/colorAccent"
        android:layout_width="match_parent"
        android:layout_height="50dp" />
</RelativeLayout>

<?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"
    tools:context=".SecondActivity">
    <TextView
        android:layout_toLeftOf="@id/right"
        android:textColor="#fff"
        android:textSize="30sp"
        android:text="左"
        android:gravity="center"
        android:id="@+id/left"
        android:background="@color/colorPrimaryDark"
        android:layout_width="match_parent"
        android:layout_height="50dp" />
    <TextView
        android:layout_alignParentRight="true"
        android:id="@+id/right"
        android:background="@color/colorAccent"
        android:text="右"
        android:textSize="30sp"
        android:textColor="#fff"
        android:gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="50dp" />
</RelativeLayout>

<?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"
    tools:context=".SecondActivity">
    <TextView
        android:gravity="center"
        android:text="左"
        android:textSize="30sp"
        android:textColor="#fff"
        android:id="@+id/left"
        android:layout_width="wrap_content"
        android:background="@color/colorAccent"
        android:layout_height="50dp" />
    <TextView
        android:gravity="center"
        android:text="右"
        android:textSize="30sp"
        android:textColor="#fff"
        android:layout_toRightOf="@id/left"
        android:background="@color/colorPrimaryDark"
        android:layout_width="match_parent"
        android:layout_height="50dp" />
</RelativeLayout>

<?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"
    tools:context=".SecondActivity">
    

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/center"
        android:background="@color/colorAccent"
        android:gravity="center"
        android:text="上"
        android:textColor="#fff"
        android:textSize="30sp" />

    <View
        android:id="@+id/center"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_centerInParent="true"></View>

    <TextView

        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/center"
        android:background="@color/colorPrimaryDark"
        android:gravity="center"
        android:text="下"
        android:textColor="#fff"
        android:textSize="30sp" />


</RelativeLayout>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章