2014-04-09 2 views
2

내 GUI에 중첩 된 레이아웃이 있습니다. 왜 그런 식으로 만들었는지 물어 보지 마십시오. 그리드 레이아웃을 사용하지 않는 이유는 무엇입니까? 제 질문은 뭔가 다른 것입니다. THISLinearLayout 새 뷰를 추가 할 때 높이가 변경됩니다.

내가 어떤보기를 추가 한 후의이 4 개 상대 레이아웃 중 하나로, 버튼을 가정 해 봅시다처럼

내 레이아웃은 내가 0dp에 상대 레이아웃의 무게를 설정 THIS

에 변경 보인다. 이렇게하면 레이아웃에 다른보기를 추가 할 때 너비가 변경되지 않습니다. 그러나 나는 그 높이에 대해 무엇을해야할지 모른다. 0dp로 설정하면, ofc가 사라집니다. 여기

내 XML 코드 :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:background="@drawable/rising_sun_blue" 
android:weightSum="2"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:layout_weight="1" 
    android:background="#333111" 
    android:weightSum="2" 
    android:layout_alignParentBottom="true" 
    > 

    <RelativeLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="#ffffff"> 
    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="#ff0000" > 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="14dp" 
      android:text="Button" /> 

    </RelativeLayout> 

</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:layout_weight="1" 
    android:background="#123132" 
    android:weightSum="2" 
    android:layout_alignParentTop="true"> 

    <RelativeLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="#ff0000"> 
    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="#ffffff"> 
    </RelativeLayout> 


</LinearLayout> 
</LinearLayout> 

그래서, 내 질문은, 것 "접착제"내 레이아웃과 그들이 정확히 첫번째 스크린 샷에 머물 수 있도록 코드의 조각이, 내가 추가 한 후 그것에있는 새로운 전망의 낱단!?

답변

2

중첩 된 LinearLayouts와 wrap_content가 아닌 layout_height = "match_parent"를 모두 지정하십시오.

관련 문제