2014-03-24 52 views
0

我想將兩個佈局放在一起。我正在使用相對佈局,並將它們放置在相對佈局中。但問題是我只得到一個佈局顯示,這是後一個。如何在相對佈局內放置兩個佈局

這裏是我的代碼:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:gravity="bottom|center" 
    android:orientation="vertical" 
    android:weightSum="1" 
    tools:context=".MainActivity" > 

    <RelativeLayout 
     android:id="@+id/relativeLayout1" 
     android:layout_width="fill_parent" 
     android:layout_height="35dip" 
     android:background="#00ACE7" 
     android:orientation="vertical" 
     android:weightSum="1" > 

     <ImageView 
      android:id="@+id/telenor_logo" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_toRightOf="@+id/telenor_logo" 
      android:src="@drawable/telenor_logo" /> 

     <ImageView 
      android:id="@+id/telenor_logo" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" 
      android:src="@drawable/telenor_logo" /> 

     <ImageButton 
      android:id="@+id/options" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentRight="true" 
      android:layout_marginRight="50dp" 
      android:background="#00ACE7" 
      android:src="@drawable/options" /> 

     <ImageButton 
      android:id="@+id/settings" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:background="#00ACE7" 
      android:src="@drawable/settings" /> 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/relativelayout2" 
     android:layout_width="fill_parent" 
     android:layout_height="35dip" 
     android:background="#B6B6B4" 
     android:visibility="visible" 
     android:weightSum="1" 
     android:layout_below="@+android:id/relative_layout1" > 
    </RelativeLayout> 

</RelativeLayout> 

回答

3

更改此屬性在第二相對佈局以下

android:layout_below="@id/relativeLayout1" 

因此,這將最終看起來像這樣

<RelativeLayout 
    android:id="@+id/relativelayout2" 
    android:layout_width="fill_parent" 
    android:layout_height="35dip" 
    android:background="#B6B6B4" 
    android:visibility="visible" 
    android:weightSum="1" 
    android:layout_below="@id/relativeLayout1"> 
</RelativeLayout> 

而且,就像快速注:

android:layout_width="fill_parent" 

(在API級別8+)應改爲:

android:layout_width="match_parent" 
+0

呀好,我這樣做,但它仍然顯示只是後者的佈局。 – Zonera

+0

您是否有必要將相對佈局作爲父項?你有沒有考慮過讓父母成爲一個具有兩個孩子相對佈局的LinearLayout? – GermaineJason

+0

是的,我已經嘗試過,但它仍然不適合我。 – Zonera