I know that ListView
objects shouldn't be put into a ScrollView
. However, I can't come up with a proper approach to this situation: I have two layouts, both including a ListView
, one directly below the other. I want all elements of both lists to be output; naturally, that should take more than the screen can offer, so I want to make the result scrollable, so, as I thought, I should put both into a ScrollView
, but this doesn't work well with ListView
(they only display one item each) and is considered a bad practice. How do I go about this?
Here's a mock up of what I mean:
Two lists, and the entirety of the second list can't fit into the screen, so I'd like to scroll it, and when I do, the second header ('Example2') scrolls up and doesn't stay in place, as opposed to the default behaviour of having the second list content scrolled.
What I have now is:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="vertical">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/example1_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ListView
android:id="@+id/example1_list_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/example1_header" />
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/example2_header />
<ListView
android:id="@+id/example2_list_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>