在一个屏幕中显示多个ListView

时间:2013-05-02 06:16:46

标签: android listview

我有2个ListView,每个从网站数据库获取信息.... 一切都很顺利,但我想要的是显示第一个listview然后在它下面第二个listview而不设置固定的高度..就像用户应该scrool到第一个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>

但即使我继续滚动,屏幕也不显示两者,只显示一个列表视图(第一个)...除非我给它们固定高度,例如android:layout_height="180dp"任何想法?

3 个答案:

答案 0 :(得分:0)

为什么不使用ExpandableListView

Example 1

Example 2

Example 3

答案 1 :(得分:0)

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

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

2.在tabview中输出它们。

3.将两个列表合并到一个列表视图中。

4.使用ExpandableListView

答案 2 :(得分:0)

你能试试吗?

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