2016-10-02 3 views
0

두 개의 목록보기, 텍스트보기 및 일부 선형 버튼을 포함하는 선형 레이아웃이 있습니다. 두 번째 listview가 첫 번째 높이의 두 배가되기를 바란다.layout_weight는 기기가 아닌 시뮬레이터에서 작동합니다.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:weightSum="3" 
    android:layout_height="match_parent"> 
    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:id="@+id/categoryList" /> 
    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="2" 
     android:id="@+id/itemList" /> 
    <TextView 
     android:id="@+id/walletStr" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 
    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
     <Button 
      android:id="@+id/cancelBtn" 
      android:text="cancel" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
     <Button 
      android:id="@+id/buyBtn" 
      android:text="buy" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
    </LinearLayout> 
</LinearLayout> 
: 여기 실제 레이아웃이다 0dp에게 모두리스트 뷰의 높이를 설정하고 상기 제 1의에 layout_weight 2 번째 가중치를주고, 다음 (3)에 포함 된 뷰의 weightSum 설정 한

시뮬레이터에서 원하는 효과가 발생하지만 실제 장치에서는 거의 모든 공간이 맨 위 목록보기로 이동합니다.

아이디어가 있으십니까? 미리 감사드립니다.

+0

외부 'LinearLayout'에서'weightSum' 속성을 제거하십시오. –

답변

0

선형 레이아웃에는 2 개의 목록이없고, 더 많은 구성 요소가 있으므로 고려해야합니다. weightSum은이 선형 레이아웃의 모든 구성 요소로 나누어 져야합니다.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:weightSum="7" 
    android:layout_height="match_parent"> 
    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="2" 
     android:id="@+id/categoryList" /> 
    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="4" 
     android:id="@+id/itemList" /> 
    <TextView 
     android:id="@+id/walletStr" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.5"/> 
    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.5"> 
     <Button 
      android:id="@+id/cancelBtn" 
      android:text="cancel" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
     <Button 
      android:id="@+id/buyBtn" 
      android:text="buy" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
    </LinearLayout> 
</LinearLayout> 
관련 문제