Używanie ListAdapter do wypełnienia LinearLayout wewnątrz układu ScrollView
Stoję w obliczu bardzo powszechnego problemu: położyłem zadanie, a teraz okazuje się, że powinien wyświetlić w nim kilka elementówScrollView
. Normalnym sposobem na to byłoby użycie istniejącegoListAdapter
, podłącz go do aListView
iBUM Miałbym listę przedmiotów.
ALE Nie należy umieszczać zagnieżdżonegoListView
wScrollView
jak to skręca przewijanie - nawet Android Lint narzeka na to.
Oto moje pytanie:
Jak podłączyć aListAdapter
do aLinearLayout
czy coś podobnego?
Wiem, że to rozwiązanie nie skaluje się dla wielu przedmiotów, ale moje listy są bardzo krótkie (<10 elementów), więc ponowne użycie widoków nie jest naprawdę potrzebne. Rozsądnie wydajne mogę żyć z umieszczaniem wszystkich widoków bezpośrednio wLinearLayout
.
Jednym z rozwiązań, które wymyśliłem, byłoby umieszczenie mojego istniejącego układu aktywności w sekcji nagłówkaListView
. Ale wydaje mi się, że nadużywasz tego mechanizmu, więc szukam czystszego rozwiązania.
Pomysły?
AKTUALIZACJA: Aby zainspirować właściwy kierunek, dodam przykładowy układ, aby pokazać mój problem:
<?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>
AKTUALIZACJA 2 Zmieniłem nagłówek, aby ułatwić zrozumienie (dostałem downvote, doh!).