2016-10-02 5 views
0

У меня есть линейная компоновка с двумя списками, текстовым видом и другой линейной компоновкой для удерживания нескольких кнопок. Я хочу, чтобы второй список был в два раза больше высоты первого. Я установил высоту обоих видов списка на 0dp и дал первый макет-вес 1, а второй - вес 2, а затем установил weightSum содержащего вида на 3. Вот фактический макет: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> 

На симуляторе это дает желаемый эффект, но на самом устройстве почти все пространство переходит в верхний список.

Любые идеи? Заранее спасибо.

+0

Удалить атрибут 'weightSum' на внешнем' LinearLayout'. –

ответ

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> 
Смежные вопросы