2011-11-28 5 views
1

내 응용 프로그램 xml 레이아웃에서, 나는 선형 레이아웃이 두 ​​개있는 Relativelayout을 가지고 있습니다. 이제는 두 레이아웃 모두에서 애니메이션을 만들고 있습니다. 그러나 thera가 다른 높이와 같아 보이기 때문에 나는 약간의보기 문제가있다.두 개의 다른 레이아웃을 동일한 높이로 만드는 방법은 무엇입니까?

그래서 두 레이아웃 모두 동일한 높이를 만들고 싶습니다. 아래 내 XML 파일입니다. 또는있는 LinearLayout로 변경 (당신이 엄격하게 필요하지 않은있는 LinearLayout 루트의 유일한 자식이기 때문에)

<!-- ============================================================= --> 
      <!-- 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_weight를 설정하는 것이 좋습니다. layout_height = '.5'둘 다에 대한 평등 한 높이를 얻을 것이다. –

+0

질문과 관련이 없지만 펜 레이아웃에서 textView와 imageview를 함께 사용하는 대신 텍스트가있는 Button과 drawableLeft 또는 drawableRight 속성으로 설정된 이미지를 사용하는 것이 좋습니다. – Marmoy

답변

1

는 포함 RelativeLayout의를 삭제합니다.

그런 다음 펜 레이아웃과 병 레이아웃 모두에 대해, 속성 안드로이드를 추가

는 레이아웃이 모두 높이가 지금

을 MATCH_PARENT로 설정했는지 확인 layout_weight를하고 1로 모두 설정하여 두 개의 레이아웃은 공간을 동일하게 공유해야하므로 동일한 높이가됩니다.

가 펜 및 병 레이아웃의 아이들 사이에 균등하게 공간을 공유하려면, 당신이 WRAP_CONTENT 각 자녀의 높이와 자식 레이아웃 1.

+0

답장을 보내 주셔서 감사합니다. 내 코드를 답안으로 업데이트하여 여기에 올리시겠습니까? –

+0

당신의 대답은 옳은 것처럼 보입니다. 하지만 저는 펜 레이아웃과 병 레이아웃에서 애니메이션을 보여주고 싶습니다. 왜 상대 레이아웃을 추가했는지. –

+0

애니메이션이 작동하려면 RelativeLayout이어야합니까? 이유를 설명해 주시겠습니까? – Marmoy