I have a ConstraintLayout
where I have three different ListView
's.
The content of these ListViews is set dynamically. So I don't really know how many items they will get on runtime.
I want the layout as follows: The first ListView should start at the top of the screen and the second should be almost right under it. (just with some fix distance). The third one should stick to the bottom of the screen, if the first two ListViews aren't taking to much space already. If they do and so they would interfere with the third ListView on the bottom, it should put below the second ListView with some fix distance.
How could I achieve this? At the moment I implemented it so that the third ListView sticks to the bottom. But it will be overwritten from the second ListView if it has too many items, or the screen of the phone is too small.
Here my Layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/backgroundColor"
android:fitsSystemWindows="true"
tools:context=".activities.fragments.PreferenceCategoryFragment">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:textAppearance="@style/introductionTitle"
android:text="Allgemeines"
app:layout_constraintTop_toTopOf="parent"/>
<View
android:id="@+id/divider1"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/darkGray"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
app:layout_constraintTop_toBottomOf="@id/title"/>
<ListView
android:id="@+id/settingsCategories"
android:layout_width="match_parent"
android:layout_height="0dp"
android:divider="@null"
app:layout_constraintTop_toBottomOf="@id/divider1">
</ListView>
<TextView
android:id="@+id/title2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="30dp"
android:textAppearance="@style/introductionTitle"
android:text="Sonstiges"
app:layout_constraintTop_toBottomOf="@id/settingsCategories"/>
<View
android:id="@+id/divider2"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/darkGray"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
app:layout_constraintTop_toBottomOf="@id/title2"/>
<ListView
android:id="@+id/settingsCategoriesLegal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:divider="@null"
app:layout_constraintTop_toBottomOf="@id/divider2">
</ListView>
<ListView
android:id="@+id/logout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:divider="@null"
android:layout_marginTop="50dp"
app:layout_constraintBottom_toBottomOf="parent">
</ListView>
</android.support.constraint.ConstraintLayout>
For better understanding see this image of how it looks like on a big screen phone:
And this is how it looks like if the screen is too small: