I have two ListViews above each other:
- When the second ListView is empty, the first ListView may fill up the whole area.
- When the first ListView is empty the second ListView may fill up the whole area.
- When both ListViews have items, the first ListView must push down the second ListView, but at least 60dp of the second ListView must be kept visible. The first ListView must not be higher than its contents.
I almost solved all these requirements with this layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@null"
android:cacheColorHint="@android:color/transparent"
/>
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:minHeight="60dp"
android:divider="@null"
android:cacheColorHint="@android:color/transparent"
/>
</LinearLayout>
When the second ListView is empty, I set the Visibility to Gone programmatically to meet the first requirement.
But when the first ListView fills up, it will push down the second ListView until it disappears.
I tried to solve this by changing the layout_height programmatically from a custom adaper when the first ListView grows too large. But my list items have different sizes, so after changing the height to a fixed value I don't know how to detect the content height when items are added or changed.
Does anybody has an idea how to solve this?