简体   繁体   English

Android如何在一个AlertDialog中一个接一个地显示两个ListView

[英]Android how to display two ListViews in one AlertDialog one after the other

I have two list. 我有两个清单。 One list show all available items (lv_available_items) and second only selected items (lv_selected_items) from available list. 一个列表显示所有可用项目(lv_available_items),第二个仅显示可用列表中的选定项目(lv_selected_items)。 I want also that selected list takes maximum 50% of display, for this I use attribute “layout_weight”. 我还希望所选列表最多显示50%的显示,为此我使用属性“ layout_weight”。 But if it's only one item from available list selected, this is not fully displayed in selected list. 但是,如果只是从可用列表中选择的一项,则不会完全显示在所选列表中。 Why? 为什么?

View for AlertDialog: 查看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>

Row for this two list: 这两个列表的行:

<?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>

Screenshots: 屏幕截图:

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

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

Try changing your height to 0dp in your ListView s 尝试在ListView 0dp height更改为0dp

<?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>

Manage the height of listview like this: 像这样管理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"/>

you will design xml according to your different emulators.Like for hdpi phone resolution design .xml file according to his view you can select hpdi emulator from graphical view in .xml file and then design different .xml for ldpi,xhdpi,etc.It is little bit time consuming but effective one 您将根据您的不同仿真器设计xml。就像hdpi手机分辨率根据其视图设计.xml文件一样,您可以从.xml文件的图形视图中选择hpdi仿真器,然后为ldpi,xhdpi等设计不同的.xml。有点耗时但有效

Then used Display metric class in .java file 然后在.java文件中使用Display metric class

  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 
    }

//Similarly another case pass Denisty_low and so on; //同样,另一种情况通过Denisty_low等等;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM