Verwenden eines ListAdapters zum Füllen eines LinearLayouts in einem ScrollView-Layout
Ich stehe vor einem sehr häufigen Problem: Ich habe eine Aktivität angelegt und nun sollte sie einige Elemente enthaltenScrollView
. Der normale Weg, dies zu tun, wäre das Vorhandene zu benutzenListAdapter
, schließen Sie es an a anListView
undBOOM Ich hätte meine Artikelliste.
ABER Sie sollten keine verschachtelten Objekte platzierenListView
in einemScrollView
wie es das Scrollen vermasselt - auch Android Lint beschwert sich darüber.
Also hier ist meine Frage:
Wie verbinde ich aListAdapter
zu einemLinearLayout
oder etwas ähnliches?
Ich weiß, dass diese Lösung nicht für viele Elemente skaliert, aber meine Listen sind sehr kurz (<10 Elemente), sodass die Wiederverwendung von Ansichten nicht wirklich erforderlich ist. Performancemäßig kann ich mit dem Platzieren aller Views direkt in dieLinearLayout
.
Eine Lösung, die ich mir ausgedacht habe, wäre, mein vorhandenes Aktivitätslayout in den HeaderView-Bereich der zu platzierenListView
. Aber das fühlt sich an, als würde man diesen Mechanismus missbrauchen, also suche ich nach einer saubereren Lösung.
Ideen?
AKTUALISIEREN: Um die richtige Richtung einzuschlagen, füge ich ein Beispiellayout hinzu, um mein Problem zu zeigen:
<?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>
UPDATE 2 Ich habe die Überschrift geändert, um das Verständnis zu erleichtern (habe eine Ablehnung, doh!).