2011-12-13 17 views
9

私はこのようなレイアウトをしたい: Desired layoutAndroid RelativeLayout - 配置方法

私のコードは動作しません。私はこのレイアウトを達成することができません、そして、私は今まで何をしたのか、何が間違っているのか分かりません。

これまで私がこれまでに持っていたことは - layout_gravityはOKですか?それとも、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> 
+2

完璧なスナップで素敵な質問。 –

答えて

15

重力または内側を使用する必要はありません。LinearLayout代わりに、layout_alignParentToplayout_alignParentLeftlayout_alignParentRightlayout_alignParentBottomlayout_centerInParentおよびlayout_centerVerticalを子供に使用してください。

RelativeLayout tutorialを通過すると便利な場合があります。

2

相対レイアウトの場合のみ、Eclipseエディタでグラフィカルレイアウトに切り替えて、属性をドラッグ&セットすることができます。すべてあなたのマウスだけで。ただし、これは他のレイアウトでは不可能です。希望が役立ちます。

関連する問題