Android RelativeLayout - 如何定位?

kra*_*moe 10 android android-layout

我想要这样的布局: 期望的布局

但我的代码不起作用.我无法实现这种布局,我不知道到目前为止我做了什么有什么问题.

这是我到目前为止 - layout_gravity好吗?还是需要将它设置在RelativeLayout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent">

    <RelativeLayout     
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">

        <TextView
            android:id="@+id/topText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="20dip"
            android:layout_gravity="top" />

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/centerLayout"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="horizontal"
            android:layout_below="@id/topText">     

            <ImageButton
                android:id="@+id/lektionBackButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"

                android:src="@drawable/back"
                android:layout_gravity="left"/>  
            <ImageView
                android:id="@+id/centerImage"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:cropToPadding="true"
                android:layout_gravity="center"/>
            <ImageButton 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/lektionForwardButton"
                android:src="@drawable/forward"
                android:layout_gravity="right"/>        
         </LinearLayout>    

         <TextView
            android:id="@+id/bottomText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="20dip"
            android:layout_below="@id/centerLayout"
            android:layout_gravity="bottom" />
    </RelativeLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

kab*_*uko 17

你根本不需要使用重力或内部LinearLayout.而是使用layout_alignParentTop,layout_alignParentLeft,layout_alignParentRight,layout_alignParentBottom,layout_centerInParentlayout_centerVertical对孩子.

通过RelativeLayout教程可能对您有用.