首页 > 解决方案 > 如何允许在单个 Activity 上滚动多个 ListView?

问题描述

我创建了一个 CV 构建应用程序,最后一个 Activity 以 ListViews 的形式显示所有信息。每个 ListView 都有 layout_height=wrap_content 这意味着一旦用户输入了多个先前的作业,数据就会从屏幕上掉下来并且无法滚动。

我已经尝试限制 ListView 使用的空间,使其自己的数据可滚动,但是这在屏幕上看起来不正确。我更希望显示所有数据并使整个屏幕可滚动。有什么建议么?

此外,我不希望用户必须移动到其他活动来查看他们输入的数据。

标签: javaandroid

解决方案


如果使用ScrollView,就可以解决。在您的 layout.xml 文件中,尝试像这样使用 ScrollView 包装所有列表视图。

...
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ListView
       android:layout_width="match_parent"
       android:layout_height="wrap_content">
   </ListView>

    <ListView
       android:layout_width="match_parent"
       android:layout_height="wrap_content">
   </ListView>
   ...
</ScrollView>
...

如果您不能解决您的问题,请查看此处


推荐阅读