2011-11-28 87 views
1

在我的應用程序xml佈局中,我有一個Relativelayout,其中有兩個線性佈局。現在我正在爲這兩個佈局做動畫。但因爲thera似乎高度不同我有一些觀點問題。如何讓兩個不同的佈局具有相同的高度?

所以我想使兩個佈局的高度相同。下面是我的xml文件。

<!-- ============================================================= --> 
      <!-- BOTTLE/PEN LAYOUT --> 
      <!-- ============================================================= --> 
      <LinearLayout android:layout_height="wrap_content" 
       android:layout_width="fill_parent" > 

       <RelativeLayout android:layout_height="wrap_content" 
        android:layout_width="fill_parent"> 
        <!-- ============================================================= --> 
        <!-- PEN LAYOUT --> 
        <!-- ============================================================= --> 
        <LinearLayout android:orientation="vertical" 
         android:layout_height="wrap_content" 
         android:layout_width="fill_parent" 
         android:id="@+id/pen_layout"> 

         <TextView 
          android:text="EF" 
          android:layout_height="wrap_content" 
          android:layout_width="wrap_content" 
          android:layout_gravity="center" 
          android:textColor="#000000" 
          android:layout_marginTop="2dp" 
          android:textSize="10sp"/> 

         <ImageView     
          android:id="@+id/save"     
          android:layout_width="wrap_content"     
          android:layout_height="wrap_content" 
          android:layout_gravity="right" 
          android:src="@drawable/ink_pen"/>    

         <TextView 
          android:text="F" 
          android:layout_height="wrap_content" 
          android:layout_width="wrap_content" 
          android:layout_gravity="center" 
          android:textColor="#000000" 
          android:layout_marginTop="2dp" 
          android:textSize="10sp"/> 
         <ImageView     
          android:id="@+id/save"     
          android:layout_width="wrap_content"     
          android:layout_height="wrap_content" 
          android:layout_gravity="right" 
          android:src="@drawable/ink_pen"/>    

         <TextView 
          android:text="BOLD" 
          android:layout_height="wrap_content" 
          android:layout_width="wrap_content" 
          android:layout_gravity="center" 
          android:textColor="#000000" 
          android:layout_marginTop="2dp" 
          android:textSize="10sp"/> 
         <ImageView     
          android:id="@+id/save"     
          android:layout_width="wrap_content"     
          android:layout_height="wrap_content" 
          android:layout_gravity="right" 
          android:src="@drawable/ink_pen"/>    

         <TextView 
          android:text="ITALIC" 
          android:layout_height="wrap_content" 
          android:layout_width="wrap_content" 
          android:layout_gravity="center" 
          android:textColor="#000000" 
          android:layout_marginTop="2dp" 
          android:textSize="10sp"/> 
         <ImageView     
          android:id="@+id/save"     
          android:layout_width="wrap_content"     
          android:layout_height="wrap_content" 
          android:layout_gravity="right" 
          android:src="@drawable/ink_pen"/> 

        </LinearLayout> 

        <!-- ============================================================= --> 
        <!-- BOTTLE LAYOUT --> 
        <!-- ============================================================= --> 

        <LinearLayout android:orientation="vertical" 
         android:layout_height="wrap_content" 
         android:layout_width="fill_parent" 
         android:weightSum="4" 
         android:id="@+id/bottle_layout"> 

         <!-- First Row Bottle --> 
         <LinearLayout android:orientation="horizontal" 
          android:layout_height="wrap_content" android:layout_weight="1" 
          android:layout_width="fill_parent" android:weightSum="2"> 
          <ImageView android:layout_height="wrap_content" android:layout_weight="1" 
           android:layout_width="wrap_content" android:src="@drawable/purple_bottle"/> 
          <ImageView android:layout_height="wrap_content" android:layout_weight="1" 
           android:layout_width="wrap_content" android:src="@drawable/red_bottle"/> 
         </LinearLayout> 

         <!-- Second Row Bottle -->    
         <LinearLayout android:orientation="horizontal" 
          android:layout_height="wrap_content" android:layout_weight="1" 
          android:layout_width="fill_parent" android:weightSum="2"> 
          <ImageView android:layout_height="wrap_content" android:layout_weight="1" 
           android:layout_width="wrap_content" android:src="@drawable/gray_bottle"/> 
          <ImageView android:layout_height="wrap_content" android:layout_weight="1" 
           android:layout_width="wrap_content" android:src="@drawable/green_bottle"/> 
         </LinearLayout> 

         <!-- Third Row Bottle -->    
         <LinearLayout android:orientation="horizontal" 
          android:layout_height="wrap_content" android:layout_weight="1" 
           android:layout_width="fill_parent" android:weightSum="2"> 
          <ImageView android:layout_height="wrap_content" android:layout_weight="1" 
           android:layout_width="wrap_content" android:src="@drawable/orange_bottle"/> 
          <ImageView android:layout_height="wrap_content" android:layout_weight="1" 
           android:layout_width="wrap_content" android:src="@drawable/blue_bottle"/> 
         </LinearLayout> 

         <!-- Forth Row Bottle -->    
         <LinearLayout android:orientation="horizontal" 
          android:layout_height="wrap_content" android:layout_weight="1" 
          android:layout_width="fill_parent" android:weightSum="2"> 
          <ImageView android:layout_height="wrap_content" android:layout_weight="1" 
           android:layout_width="wrap_content" android:src="@drawable/black_bottle"/> 
          <ImageView android:layout_height="wrap_content" android:layout_weight="1" 
           android:layout_width="wrap_content" android:src="@drawable/white_bottle"/> 
         </LinearLayout> 

        </LinearLayout> 
       </RelativeLayout> 
      </LinearLayout> 
+0

使用重量爲子佈局。 layout_height ='。5',你會得到相同的高度。 –

+0

與你的問題沒有關係,但我可以建議你的筆佈局,而不是像你一樣使用textView和imageview,使用按鈕與文本和圖像設置爲按鈕drawableLeft或drawableRight屬性? – Marmoy

回答

1

刪除包含RelativeLayout的(因爲它是你的根的獨子的LinearLayout你不嚴格需要它)或將其更改爲LinearLayout中。

然後同時爲筆佈局和瓶子佈局,添加屬性的android:layout_weight並把它們設置爲1

確保兩個佈局都設置高度爲MATCH_PARENT

現在你兩個佈局應該在它們之間平均分配空間,從而使它們的高度相同。

平等共享筆和瓶佈局的孩子之間的空間,我建議你設定每個孩子的高度和WRAP_CONTENT每個孩子的layout_weight爲1

+0

感謝您的回覆。請你用你的答案更新我的代碼並放在這裏? –

+0

你的答案似乎是正確的。但我想顯示筆的佈局和瓶佈局這就是爲什麼我添加了相對佈局的動畫。 –

+0

是否必須是動畫的RelativeLayout才能使用?你能解釋爲什麼嗎? – Marmoy

相關問題