2012-01-24 36 views
0

我正試圖實現兩個嵌套相對佈局佔用相等數量的空間並填充整個屏幕寬度。所有父級佈局在寬度上都有fillparent設置。在Eclipse中的圖形視圖看起來很好,但我的HTC不同意 - 它將它們粘在一起(我很好),但它也將它們轉移到左邊。我希望他們伸展。在父佈局中拉伸兩個佈局

<LinearLayout 
     android:id="@+id/footer" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" > 

     <RelativeLayout 
      android:id="@+id/relativeLayout1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      > 

      <ImageButton 
       android:id="@+id/button_1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@android:color/transparent" 
       android:src="@drawable/button_1_active" > 
      </ImageButton> 

      <TextView 
       android:id="@+id/TextView01" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerInParent="true" 
       android:text="@string/partners_info" 
       android:textColor="@color/white" 
       android:textStyle="bold" > 
      </TextView> 
     </RelativeLayout> 

     <RelativeLayout 
      android:id="@+id/relativeLayout2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      > 

      <ImageButton 
       android:id="@+id/button_2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@android:color/transparent" 
       android:src="@drawable/button_2_inactive" > 
      </ImageButton> 

      <TextView 
       android:id="@+id/TextView02" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerInParent="true" 
       android:text="@string/partners_map" 
       android:textColor="@color/white" 
       android:textStyle="bold" > 
      </TextView> 
     </RelativeLayout> 
    </LinearLayout> 
+0

採用Android:layout_weight – nik431

+0

@Ana你'RelativeLayout'有自己的'layout_width'設置到'wrap_content'。您應該將其更改爲'fill_parent'來填充所有空間。 – Luksprog

+0

我真的應該把它做得更好 - 兩種佈局使用相同數量的空間,並且它們被拉伸。現在我需要讓這兩個ImageButton展開到每個RelativeLayouts。我已經將它們的寬度設置爲fillparent,並將高度設置爲包裝內容。但他們在兩邊都有白色的空白空間... – Ana

回答

1

對於兩個ImageButton嘗試將layout_width屬性設置爲fill_parent,然後又補充:

android:scaleType="fitXY" 
+0

工作就像一個魅力! – Ana

0

對他們使用相同的空間,你將不得不設置layout_weight等於號碼來獲得。

+0

他們使用相同的空間,但不是行中的剩餘空間......我需要將它們拉伸到父項。 – Ana

0

使用此layout_weight = 1。兩個RelativeLayout的

<RelativeLayout 
     android:id="@+id/relativeLayout1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     > 
+0

這並不能解決問題。現在第一個設置在行的開始位置,另一個位於行的中間位置;他們之後都有空餘的空間。 – Ana

+0

使用linearlayout來代替RelativeLayout。爲什麼使用RelativeLayout有什麼原因? – NagarjunaReddy

+0

不是我的代碼,也不是真的「允許」進行隨機更改。看起來很愚蠢,而且是。 – Ana