2013-10-08 97 views
0

我有兩個列表。一個列表顯示可用列表中的所有可用項目(lv_available_items)和僅次要項目(lv_selected_items)。我還希望該選定列表最多佔用顯示的50%,因此我使用屬性「layout_weight」。但是,如果只選擇了可用列表中的一個項目,則這不會在選定列表中完全顯示。爲什麼?Android如何在一個AlertDialog中一個接一個地顯示兩個ListViews

信息查看AlertDialog:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:weightSum="1" > 

    <ListView 
     android:id="@+id/lv_selected_items" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.5" 
     android:background="@android:color/darker_gray"> 
    </ListView> 

    <ListView 
     android:id="@+id/lv_available_items" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.5" > 
    </ListView> 
</LinearLayout> 

行這兩個列表:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="left|center_vertical" 
    android:orientation="horizontal" > 

    <TextView 
     android:id="@+id/tv" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="right|center_vertical" > 

     <CheckBox 
      android:id="@+id/cb" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:onClick="onClickRow"/> 
    </LinearLayout> 
</LinearLayout> 

截圖:

http://windows.valloc.de/msl1.png

http://windows.valloc.de/msl2.png

回答

0

試着改變你的ListView小號

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:weightSum="1" > 

    <ListView 
     android:id="@+id/lv_selected_items" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.5" 
     android:background="@android:color/darker_gray"> 
    </ListView> 

    <ListView 
     android:id="@+id/lv_available_items" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.5" > 
    </ListView> 
</LinearLayout> 
+0

我試過了,但同樣的問題。 – CroCop

0

height0dp管理的ListView的高度是這樣的:

<?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" > 
    <ListView 
    android:layout_width="match_parent" 
    android:layout_height="250dp" 
    android:id="@+id/lv1" 
    android:scrollingCache="false"/> 
<ListView 
    android:layout_width="match_parent" 
    android:layout_height="200dp" 
    android:id="@+id/lv1" 
    android:scrollingCache="false"/> 

+0

是的,我可以做到這一點,但我不想要一個固定的大小,爲不同的設備。 – CroCop

+0

試試這些方法之一是設置高度wrap_content,另一個是設計自定義listview。 –

-1

你會根據您的不同emulators.Like設計XML hdpi手機分辨率設計.xml文件根據他的觀點,您可以從.xml文件的圖形視圖中選擇hpdi模擬器,然後爲ldpi,xhdpi等設計不同的.xml。它是l ittle位費時,但有效的一種

然後使用顯示度量類在java文件

DisplayMetrics metrics = new DisplayMetrics(); 
    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); 
    screenWidthPX = metrics.widthPixels; 
    screenHeightPX = metrics.heightPixels; 
    densityDpi = metrics.densityDpi; 
    switch(metrics.denistyDpi) 
    { 
     case DisplayMetrics.Denisty_High: 
     R.id.high.xml; //pass xml id of high denisty 
    } 

//類似地另一種情況下通過Denisty_low等;

+0

這個答案是完全不相關的問題。 –

相關問題