2011-12-11 76 views
3

我希望我的整个活动立即滚动,但嵌入在我的ScrollView中的ListView不会展开。我只看到第一行,但是当滚动listView时,我可以滚动浏览其他行。 我需要的是为ListView高度扩展使其包含无需滚动列表视图,只有主滚动视图显示每个项目......Android:如何让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> 
+0

你可以参考这篇文章http://stackoverflow.com/questions/3495890/how-can-i-put-a-listview-into-a-scrollview-without-it-collapsing –

回答

4

其中一个主要目的的一个ListView是在滚动时启用细胞回收。如果你想要所有的单元格都存在,那么你不需要一个ListView。只需使用垂直方向的LinearLayout。

+0

你是完全正确的! 我真的不需要一个ListView,我可以用一个简单的LinearLayout获得相同的结果。我只需要手动处理分频器。 – user1026605

相关问题