I've a constraintLayout which is wrapped with ScrollView in my activity. The activity layout has a GuidleLine on the top, a fragment with height of 0dp and a textView constrained to the bottom of the activity The problem is that the fragment doesn't take the entire space it needs to display it's views completely.
This is the activity layout code:
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=" Upper TEXT"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/guideline"
app:layout_constraintBottom_toTopOf="@id/nav_host_fragment"/>
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:defaultNavHost="true"
android:layout_marginTop="10dp"
app:layout_constraintBottom_toTopOf="@id/bottomText"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/text"
app:navGraph="@navigation/nav_graph" />
<TextView
android:id="@+id/bottomText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=" Bottom TEXT"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/nav_host_fragment"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
This is the fragment layout code:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".FirstFragment">
<com.google.android.material.button.MaterialButton
android:id="@+id/button_first"
android:layout_width="100dp"
android:layout_height="56dp"
android:text="Button"
android:textColor="@color/white"
android:gravity="center"
android:backgroundTint="@android:color/holo_red_dark"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/button2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/button2"
android:layout_width="100dp"
android:layout_height="56dp"
android:text="Button 2"
android:textColor="@color/white"
android:gravity="center"
android:backgroundTint="@android:color/black"
app:layout_constraintTop_toBottomOf="@id/button_first"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/button3"
android:layout_width="100dp"
android:layout_height="56dp"
android:text="Button 2"
android:textColor="@color/white"
android:gravity="center"
android:layout_marginTop="100dp"
android:backgroundTint="@android:color/black"
app:layout_constraintTop_toBottomOf="@id/button2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/button4"
android:layout_width="100dp"
android:layout_height="56dp"
android:text="Button 2"
android:textColor="@color/white"
android:gravity="center"
android:layout_marginTop="50dp"
android:backgroundTint="@android:color/black"
app:layout_constraintTop_toBottomOf="@id/button3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
The result is that the activity is not scrolling and the fragment is cut.
I tried giving the fragment wrap_content height, but it makes the scrolling very heavy and stugglish and it some cases it's causing other problem.
Please help :-)