This method is the layout equivalent of plotting arbitrary X and Y coordinates.
Features:
- The child objects are automatically centered in the RelativeLayout whether you use it as the top-level layout or embed it in another.
- For N images your layout contains only N+1 views.
This example layout shows how to place an ImageView in each quadrant of an XY grid with origin at the center:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/center"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_centerInParent="true"
android:background="#FFFF0000"
/>
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#FF00FF00"
android:layout_above="@id/center"
android:layout_toLeftOf="@id/center"
android:layout_marginRight="100dp"
android:layout_marginBottom="25dp"
/>
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#FF00FF00"
android:layout_below="@id/center"
android:layout_toLeftOf="@id/center"
android:layout_marginRight="100dp"
android:layout_marginTop="25dp"
/>
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#FF00FF00"
android:layout_above="@id/center"
android:layout_toRightOf="@id/center"
android:layout_marginLeft="100dp"
android:layout_marginBottom="25dp"
/>
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#FF00FF00"
android:layout_below="@id/center"
android:layout_toRightOf="@id/center"
android:layout_marginLeft="100dp"
android:layout_marginTop="25dp"
/>
</RelativeLayout>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…