Android 如何在同一活动中添加多个ListView?

Android 如何在同一活动中添加多个ListView?,android,listview,scrollview,Android,Listview,Scrollview,我想在一个活动中显示两个listview,动态加载listview中的内容。我想在第二个listview下添加更多组件。当我使用scrollview时,每个listview中只能看到一行。不使用scrollview,可以看到listview中的所有内容。但无法看到第二个listview下的组件。有人能帮我在一个活动中添加多个可展开的listview吗???尝试添加以下内容到您的滚动视图: <?xml version="1.0" encoding="utf-8"?> <Linea

我想在一个活动中显示两个listview,动态加载listview中的内容。我想在第二个listview下添加更多组件。当我使用scrollview时,每个listview中只能看到一行。不使用scrollview,可以看到listview中的所有内容。但无法看到第二个listview下的组件。有人能帮我在一个活动中添加多个可展开的listview吗???

尝试添加以下内容到您的滚动视图:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/lyt_stats"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/plain_bg"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/lyt_statsheader"
        android:layout_width="match_parent"
        android:layout_height="42dip"
        android:background="@drawable/headerbar_stats"
        android:orientation="vertical" >

        <include
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            layout="@layout/statsheader" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/txtworktcompltd"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dip"
            android:layout_marginRight="10dip"
            android:layout_marginTop="10dip"
            android:text="@string/workt_completed"
            android:textColor="@color/Black"
            android:textSize="22dip"
            android:textStyle="bold" />

        <ListView
            android:id="@+id/listViewwoktcompleted"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_marginLeft="10dip"
            android:layout_marginRight="10dip"
            android:layout_marginTop="5dip"
            android:layout_weight="1"
            android:background="@color/White"
            android:cacheColorHint="#00000000"
            android:listSelector="@android:color/transparent" />

        <TextView
            android:id="@+id/txtTotalworktTime"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dip"
            android:layout_marginTop="5dip"
            android:text="@string/workttotal_time"
            android:textColor="@color/Black"
            android:textSize="22dip" />

        <TextView
            android:id="@+id/txtexcompltd"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dip"
            android:layout_marginTop="5dip"
            android:text="@string/ex_completed"
            android:textColor="@color/Black"
            android:textSize="22dip"
            android:textStyle="bold" />

        <ListView
            android:id="@+id/listViewexcompleted"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_marginLeft="10dip"
            android:layout_marginRight="10dip"
            android:layout_marginTop="5dip"
            android:layout_weight="1"
            android:background="@color/White"
            android:cacheColorHint="#00000000"
            android:minHeight="0dip" />

        <TextView
            android:id="@+id/txtTotalEx"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dip"
            android:text="@string/extotal"
            android:textColor="@color/Black"
            android:textSize="22dip" />

        <TextView
            android:id="@+id/txtweightloss"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dip"
            android:text="@string/txtweightlossed"
            android:textColor="@color/Black"
            android:textSize="22dip"
            android:textStyle="bold" />
    </LinearLayout>

</LinearLayout>   

我很久以前就做过了。我想我把TextView/ListView分别包装成了一个线性布局。TextView具有固定的高度,而ListView具有填充父内容或换行内容。然后,我将权重添加到LinearLayout中,并将它们包装到另一个LinearLayout中。但这只适用于拆分屏幕,不适用于可扩展。当我必须使用可扩展部分执行两部分listview时,我在listview项周围添加了一个包装器对象,并通过适配器根据类型呈现不同的项。带有SectionHeader的标识符之一,它将在两个ListView之间成为TextView的一部分。工作得很有魅力。不需要滚动视图。这很流行。您可以搜索并计算listview高度。根据项目数计算listview高度。未针对当前问题获得任何正确的解决方案,在这里,我使用自定义适配器类添加每个项目。我希望根据项目增加高度。我还希望在第二个listview下显示一些组件。加载第二个listview时,自动更改第一个listview的大小。请大家知道解决方案??当我添加android:fillViewport=“true”时要滚动查看每个listview,只需显示2行。它不起作用。。
android:fillViewport="true"