Je suis confronté à un problème très courant: j'ai mis en page une activité et il s'avère maintenant qu'elle devrait afficher quelques éléments à l'intérieur ScrollView. La manière normale de faire cela serait d'utiliser l'existant ListAdapter, de le connecter à un ListViewet BOOM j'aurais ma liste d'articles.
MAIS vous ne devriez pas placer un imbriqué ListViewdans un ScrollViewcar il bousille le défilement - même Android Lint s'en plaint.
Alors voici ma question:
Comment connecter un ListAdapterà un LinearLayoutou quelque chose de similaire?
Je sais que cette solution ne s'adapte pas à beaucoup d'éléments, mais mes listes sont très courtes (<10 éléments), donc la réutilisation des vues n'est pas vraiment nécessaire. En termes de performances, je peux vivre en plaçant toutes les vues directement dans le LinearLayout.
Une solution que j'ai trouvée serait de placer ma disposition d'activité existante dans la section headerView du ListView. Mais cela donne l'impression d'abuser de ce mécanisme, alors je cherche une solution plus propre.
Des idées?
MISE À JOUR: Afin d'inspirer la bonne direction, j'ajoute un exemple de mise en page pour montrer mon problème:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/news_detail_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:visibility="visible">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFF"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingLeft="@dimen/news_detail_layout_side_padding"
android:paddingRight="@dimen/news_detail_layout_side_padding"
android:paddingTop="@dimen/news_detail_layout_vertical_padding"
android:paddingBottom="@dimen/news_detail_layout_vertical_padding"
>
<TextView
android:id="@+id/news_detail_date"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="center_horizontal"
android:text="LALALA"
android:textSize="@dimen/news_detail_date_height"
android:textColor="@color/font_black"
/>
<Gallery
android:id="@+id/news_detail_image"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:paddingTop="5dip"
android:paddingBottom="5dip"
/>
<TextView
android:id="@+id/news_detail_headline"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="center_horizontal"
android:text="Some awesome headline"
android:textSize="@dimen/news_detail_headline_height"
android:textColor="@color/font_black"
android:paddingTop="@dimen/news_detail_headline_paddingTop"
android:paddingBottom="@dimen/news_detail_headline_paddingBottom"
/>
<TextView
android:id="@+id/news_detail_content"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="Here comes a lot of text so the scrollview is really needed."
android:textSize="@dimen/news_detail_content_height"
android:textColor="@color/font_black"
/>
<!---
HERE I NEED THE LIST OF ITEMS PROVIDED BY THE EXISTING ADAPTER.
They should be positioned at the end of the content, so making the scrollview smaller is not an option.
---->
</LinearLayout>
</ScrollView>
</LinearLayout>
MISE À JOUR 2 J'ai changé le titre pour le rendre plus facile à comprendre (j'ai obtenu un vote défavorable, doh!).