2011-12-11 70 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

相關問題