2011-12-11 3 views
3

Je veux que mon activité entière défile à la fois, mais le ListView qui est incorporé dans mon ScrollView ne s'élargira pas. Je vois juste la première rangée, mais je peux faire défiler les autres rangées, en faisant défiler la liste. Ce que je besoin est pour le listView de se développer en hauteur pour tous les éléments qu'il contient sont affichés sans avoir à faire défiler la listview, seule la principale ScrollView ...Android: comment faire un listview remplir son parent sans défilement?

<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

Vous pouvez vous référer à cet article http://stackoverflow.com/questions/3495890/how-can-i-put-a-listview-into-a-scrollview-without-it-collapsing –

Répondre

4

L'un des principaux objectifs d'un ListView est de activer le recyclage des cellules lors du défilement. Si vous voulez que toutes les cellules existent, vous n'avez pas besoin de ListView. Utilisez simplement un LinearLayout orienté verticalement.

+0

vous avez totalement raison ! Je n'ai pas vraiment besoin d'un ListView, je peux obtenir le même résultat avec un LinearLayout simple. J'ai juste besoin de manipuler les diviseurs à la main. – user1026605

Questions connexes