I am using Collapsing toolbar layout in my project in which I am using one NestedScrollView in which I have multiple Card Views in which the content is not static instead it changes in onActivityResult. I have set minimum height of CollapsingToolbarLayout as 100dp. So I have observed couple of issues in it:
- On big phones the content scrolls up to minimum height 100dp leaving a large empty space at bottom which is not desired result. It should scroll up only when it is necessary. Necessary Condition is that when I get large text value in Text fields it should scroll otherwise not.
- I have used Natario Solution in it which calculates minimum height of
CollapsingToolbarLayoutdynamically which works somehow but it vanish the scroll ability ofNestedScrollViewIf I get large dynamic texts, which is not desired result.
My layout.xml file is:-
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:clickable="true"
android:id="@+id/topBlock"
app:layout_constraintTop_toTopOf="parent"
android:focusable="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
xmlns:android="http://schemas.android.com/apk/res/android">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/navigation"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
app:elevation="0dp"
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="@null"
android:minHeight="100dp">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapse_bar"
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="@android:color/holo_blue_light"
android:minHeight="100dp"
app:layout_collapseMode="parallax"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:layout_scrollInterpolator="@android:anim/decelerate_interpolator">
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/camera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="8dp"
app:backgroundTint="@color/white"
app:fabSize="normal"
app:layout_anchor="@+id/nestedScrollView"
app:layout_anchorGravity="top|center_horizontal"
app:srcCompat="@drawable/ic_launcher_background" />
<androidx.core.widget.NestedScrollView
android:id="@+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:background="@color/white"
android:layout_height="wrap_content">
////My Scrolling Content(Contains many edit texts so its size may vary)
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
I have not done anything in MyActivity.kt file. Please help me out this. I have tried nearly all solutions in this community from last 15 days still no luck. Thanks!!
Edit: As Suggested I have updated the Question with NestedScrollView as direct child and posted Screenshot of Android Studio preview in which it is taking height which is crossing preview. It should take height according to the content.If I make NestedScrollView wrap_content then still it leaves empty space at bottom. In background I have Camera running so I have to make it match parent to make cover full height.
