安卓RelativeLayout相对布局
实现左右上下中心UI界面设计
效果图:
在这里插入代码片
<?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"
android:gravity="center"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="中心"
android:layout_centerInParent="true"
android:id="@+id/center1"
android:textSize="30dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="上方"
android:id="@+id/above1"
android:textSize="30dp"
android:layout_above="@id/center1"
android:layout_alignLeft="@id/center1"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="下方"
android:id="@+id/below1"
android:textSize="30dp"
android:layout_below="@id/center1"
android:layout_alignLeft="@id/center1"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="左方"
android:id="@+id/left1"
android:textSize="30dp"
android:layout_toLeftOf="@id/center1"
android:layout_alignBottom="@id/center1"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="右方"
android:id="@+id/right1"
android:textSize="30dp"
android:layout_toRightOf="@id/center1"
android:layout_alignBottom="@id/center1"
/>
</RelativeLayout>