安卓 : split the screen in 2 equals parts with 2 listviews

标签 android listview android-layout

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

我试图将两个 ListView 的权重设置为 1,但没有成功:

=> 如果第一个 ListView 只有 1 个项目而第二个 ListView 有 99 个项目,则您看不到 ListView #1 的第一个项目 => 它缩小得太多(相对于 ListView #2)以至于您看不到

所以我现在正在考虑将屏幕分成 2 个相等的部分(无论每个 ListView 的大小如何)并将两个 ListView 放在每个部分中。当然,它需要在任何设备上运行...那么我如何捕获设备屏幕尺寸,将其一分为二并强制 ListView 尺寸适合屏幕的每一半?

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

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

休伯特

最佳答案

我只需要将我的 2 个 ListView “封装”到 2 个单独的线性布局中 => 这 2 个线性布局的权重为 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>

关于安卓 : split the screen in 2 equals parts with 2 listviews ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3968171/

相关文章:

java - 安卓库 : activeandroid index and unique annotation not available

android - 如何在android上的sqlite中将.sqlite导入数据库

C# WPF - ListView 项目到 TextBox

java - 如何为使用 setListAdapter 填充的 Listview 设置主题

android - 是否可以将这些文件夹分配到另一个地方?

android - 如何将最小 DatePicker 日期设置为当前日期

Android:如何使 ListView 在不滚动的情况下填充其父级?

java - 如何使用后退堆栈或通过此特定寻呼机适配器获取 getChildFragmentManager() 以便使用后退按钮?

android - 在 Android Studio XML 的预览部分显示自定义字体或 View

android - 为什么Android layer-list drawable如此智能?