Android 在一个屏幕中显示多个列表视图

Android 在一个屏幕中显示多个列表视图,android,listview,Android,Listview,我有2个ListView,每个都从网站数据库中获取信息。。。。 一切都很顺利,但我想显示的是第一个listview,然后在它下面显示第二个listview,而不设置固定的高度。。与此类似,用户应该滚动到第一个listview的末尾,然后在不显示滚动条的情况下显示第二个listview。以下是我所做的: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http:

我有2个ListView,每个都从网站数据库中获取信息。。。。 一切都很顺利,但我想显示的是第一个listview,然后在它下面显示第二个listview,而不设置固定的高度。。与此类似,用户应该滚动到第一个listview的末尾,然后在不显示滚动条的情况下显示第二个listview。以下是我所做的:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ListView
        android:id="@+id/firstlist"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    </ListView>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

    <ListView
        android:id="@+id/secondlist"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         >
     </ListView>
    </RelativeLayout>

</LinearLayout>


但即使我一直滚动,屏幕也不会同时显示这两个视图,只会显示一个listview(第一个)。。。除非我给他们固定高度,比如android:layout\u height=“180dp”有什么想法吗?

为什么不使用
ExpandableListView


我以前也有同样的问题。以下是四种解决方案:

1.为每个列表视图提供
android:layout_weight=“1”
,以便它们可以将屏幕减半

2.将它们放在选项卡视图中

3.将两个列表合并到一个listview中


4.使用ExpandableListView

您能试试这个吗

<?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:id="@+id/listView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1" >
</ListView>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="5dp"
    android:background="#C0C0C0" >
</LinearLayout>

<ListView
    android:id="@+id/listView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1" >
</ListView>


好吧,我仍然需要滚动它们,两个listview从一半开始显示在同一屏幕上。我认为第2个是更好的解决方案。只要我不能合并它们或将它们放在ExpandableListView中,因为它们都有自己的信息。没问题,它会处理这个问题。你是对的,非常感谢,但我想我会关注tabview,因为我认为它可以提供一个很好的界面。。