【问题标题】:Android: how to make a listview fill its parent without scrolling?Android:如何让列表视图在不滚动的情况下填充其父级?
【发布时间】:2011-12-11 15:19:53
【问题描述】:

我希望我的整个活动一次滚动,但嵌入在我的 ScrollView 中的 ListView 不会展开。我只看到第一行,但在滚动 listView 时,我可以滚动浏览其他行。 我需要的是让 listView 扩展高度,以便显示它包含的每个项目,而无需滚动 listview,只有主 scrollView...

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

【问题讨论】:

标签: android listview scrollview


【解决方案1】:

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

【讨论】:

  • 你完全正确!我真的不需要 ListView,我可以使用简单的 LinearLayout 获得相同的结果。我只需要手动处理分隔线。
猜你喜欢
  • 2013-10-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-06
相关资源
最近更新 更多