2014-03-24 102 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