Android:如何让listview填充其父级而不滚动?

时间:2011-12-11 15:19:54

标签: android listview scrollview

我希望我的整个活动立即滚动,但嵌入在我的ScrollView中的ListView将不会展开。我只看到第一行,但滚动listView时我可以滚动浏览其他行。 我需要的是listView的高度扩展所以它包含的每个项目都显示而不必滚动列表视图,只有主滚动... ...

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:orientation="vertical"
        android:layout_weight="1" >
        <LinearLayout
            android:id="@+id/header_Layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal" >

        ...

        </LinearLayout>
        <TextView
            android:id="@+id/comment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginTop="5dp"
            android:background="@drawable/gradient_background"
            android:text="@string/comments"
            android:textColor="#000000"
            android:textStyle="bold" >
        </TextView>

        <ListView
            android:id="@+id/commentsListView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="fill"
            android:divider="@drawable/gradient_divider"
            android:dividerHeight="1dp" />
    </LinearLayout>
</ScrollView>

1 个答案:

答案 0 :(得分:4)

ListView的主要目的之一是在滚动时启用单元格的回收。如果您希望所有单元格都存在,那么您不需要ListView。只需使用垂直方向的LinearLayout。