Le ScrollView avec une ListView n'a pas de défilement android
Mon problème avec la mise en page suivante, c'est que la mise en page n'a pas de défilement. Mon exigence est que j'ai à l'écran 2 listes, qui parfois peut être grand. Donc j'ai mis les ListViews à l'intérieur d'un ScrollView afin que je puisse faire défiler vers le bas et ont un look à la fois les ListViews. I don't want the ListView to scroll
. Je veux seulement mon ScrollView à se comporter comme il se doit. Toutes les suggestions??
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scrollViewContactDetails"
android:layout_width="match_parent"
android:layout_height="fill_parent" android:fillViewport="true">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="22dp" />
<LinearLayout
android:id="@+id/numbersLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:orientation="vertical"
android:weightSum="1" >
<LinearLayout
android:id="@+id/numbersLayoutList"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical"
android:weightSum="1" >
<ListView
android:id="@+id/numbersList"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:dividerHeight="2dp" >
</ListView>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/emailLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:weightSum="1" >
<LinearLayout
android:layout_width="120dp"
android:layout_height="match_parent"
android:layout_gravity="right|center"
android:gravity="top|right"
android:orientation="vertical" >
<TextView
android:id="@+id/emailId"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="right|center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#8d8d8d"
android:textSize="18dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/emailLayoutList"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="20dp"
android:gravity="center"
android:orientation="vertical"
android:weightSum="1" >
<ListView
android:id="@+id/emailList"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_weight="1"
android:dividerHeight="2dp" >
</ListView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Check this out: stackoverflow.com/a/3193909/1118475
OriginalL'auteur Vikram Gupta | 2013-02-05
Vous devez vous connecter pour publier un commentaire.
J'ai passé des jours à essayer de comprendre comment atteindre cet objectif et ne pouvais pas trouver une solution.
You should not put a ListView inside a ScrollView
est commun de dire partout où j'ai cherché. Je ne voulais pas utiliser de LinearLayout ou ViewGroup parce que j'avais déjà créé l'ensemble de l'INTERFACE utilisateur à l'aide de ListView, et c'était génial pour moi et pour tout le monde. Il a bien fonctionné, sauf que la page n'a pas de défilement.Récemment je suis tombé sur une question ici, et de la pensée de donner cette réponse de l'essayer. Il fonctionne parfaitement!
Voici la solution:
Appelez simplement
Utility.setListViewHeightBasedOnChildren(yourListView)
après que vous avez attribué à la carte de votre listview et vous avez terminé!Un grand merci à
DougW
de venir avec la réponse. Voici le lien d'origine Comment puis-je mettre un ListView dans un ScrollView sans qu'il s'effondre?OriginalL'auteur Vikram Gupta
Vous ne devez pas mettre listview dans le scrollview, ce n'est pas une bonne idée. Si vous ne voulez pas que ça à faire défiler, peut-être que vous ne devriez pas utiliser listviews. Avez-vous essayé avec LinearLayouts?
OriginalL'auteur Michał Z.
Au lieu de mettre les deux listview vous pouvez utiliser une listview et vous pouvez ajouter des données ou de gonfler les deux fichier xml dans l'adaptateur de la listview. Cela permettra de montrer à la fois les données dans un listview et faites défiler les données avec une barre de défilement.
OriginalL'auteur Android-iPhone-rahul
Avant d'appeler la méthode ci-dessous,
Vous devez supprimer la propriété android:fillViewport="true" dans le scrollview. Si pas, le défilement ne fonctionne.
OriginalL'auteur Thamarai T
Essayer de cette façon:
Vous avez retiré de défilement de la vue à partir de votre mise en page parce que cela ne fonctionne pas correctement pour l'affichage de la liste..
Et aussi vous mettre à la hauteur
"android:layout_height="fill_parent"
pour listview c'est donc occuper toute la hauteur de la mère de mise en page.de sorte s'il vous plaît fixer une hauteur manuellement pour les deux listview.
OriginalL'auteur Android_coder