ANDROID:将屏幕分成 2 个相等的部分,有 2 个列表视图

问题描述:

我正在尝试将 2 个列表视图放入我的布局中.问题是我事先不知道每个列表视图的大小.第一个列表视图可能有几个项目(0、1、2 到大约 10 个),第二个列表视图可能有很多项目(最多 100 个).

I'm trying to put 2 listviews into my layout. The problem is that I don't know the size of each listview in advance. The first listview could have a few items (0, 1, 2 up to roughly 10) and the second listview could have many items (up to 100).

我试图将两个列表视图的权重设置为 1,但没有奏效:

I tried to set the weight of both listviews at 1 but it did not work:

=> 如果第一个列表视图只有 1 个项目而第二个有 99 个项目,则您看不到列表视图 #1 的第一项 => 它缩小了很多(相对于列表视图 #2),您看不到

=> If the first listview has only 1 item and the second one 99, you don't see the first item of listview #1 => it's shrinks so much (relative to listview #2) that you don't see it.

所以我现在想将屏幕分成 2 个相等的部分(无论每个列表视图的大小如何/无论大小),并将两个列表视图放在每个部分中.当然它需要在任何设备上工作......那么我如何捕获设备屏幕大小,将其一分为二并强制列表视图大小适合屏幕的每一半?

So I'm thinking now to split the screen in 2 equals parts (no matter what/no matter the size of each listview) and put the two listviews in each part. Of course it needs to work on any device ... so how do I capture the device screen size, divide it in two and force the listview size to fit in each half of the screen ?

有人做过吗?是否有另一个选项可以在同一布局上显示两个不同大小的列表视图(我应该以某种方式使用滚动视图吗?=> 当用户到达第一个列表视图的末尾时,出现第二个列表视图 => 这可能吗??)

Has anyone done that already ? Is there another option to show two listviews of different sizes on the same layout (should I use a scrollview in some way ? => when the user is reaching the end of the first listview, the second listview appears => is that possible ??)

感谢您的帮助和任何建议...

Thank you for your help and any suggestion ...

休伯特

我只需要将我的 2 个列表视图封装"为 2 个单独的线性布局 => 这两个线性布局的权重为 1 :

I simply had to "encapsulate" my 2 listviews into 2 separate linearlayouts => these 2 linearlayout have a weight of 1 :

    <LinearLayout android:layout_weight="1" 
                    android:layout_height="fill_parent" 
                    android:layout_width="fill_parent">

                <ListView   android:id="@+id/ListView_NASDAQ100" 
                            android:layout_height="fill_parent" 
                            android:layout_width="fill_parent">

                </ListView>
    </LinearLayout>

<LinearLayout android:layout_weight="1" 
                android:layout_height="fill_parent" 
                android:layout_width="fill_parent">

            <ListView   android:id="@+id/ListView_from_52w_HIGHLOW" 
                        android:layout_height="fill_parent" 
                        android:layout_width="fill_parent">

            </ListView>
</LinearLayout>