The structure of my layout file: Coordinator layout - NestedScrollView - Coordinator Layout - objects that i want to be able to scroll
My TextInputLayout with TextInputEditText is at the bottom of the screen and when filled, extends out of bounds of the screen. When I collapse the keyboard it’s still not scrollable.
Note: I don’t want to set maxLines to Edittext and make it scrollable itself. I want it to scroll with other elements.
However, if I put, for example, TextView at the bottom of the screen and it doesn’t fit, the page is scrollable. Any ideas?
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--other items i want to scroll-->
<com.google.android.material.textfield.TextInputLayout
android:id="@ id/descriptionLayout"
android:layout_width="348dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="545dp"
android:ems="16"
android:fontFamily="@font/montserrat"
android:hint="Add image description (optional)"
android:inputType="textMultiLine|textAutoCorrect"
app:counterEnabled="true"
app:counterMaxLength="256"
app:boxBackgroundColor="@color/white"
app:srcCompat="@drawable/ic_round_cloud_upload_24"
android:textColor="#68B2A0"
android:textColorHint="#68B2A0"
app:hintTextColor="#68B2A0"
app:layout_anchor="@id/titleLayout"
app:boxStrokeErrorColor="#F75010"
app:boxStrokeColor="#68B2A0"
app:boxStrokeWidth="2dp"
app:errorIconTint="@color/error"
app:errorTextColor="@color/error"
app:layout_anchorGravity="center|bottom"
app:counterOverflowTextColor="@color/error"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:counterTextColor="@color/main_green"
>
<com.google.android.material.textfield.TextInputEditText
android:id="@ id/descriptionTxt"
android:ems="16"
android:textSize="18sp"
android:textColor="#68B2A0"
android:fontFamily="@font/montserrat"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:maxLines="7"
/>
</com.google.android.material.textfield.TextInputLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.core.widget.NestedScrollView>
<!--bottom app bar-->
</androidx.coordinatorlayout.widget.CoordinatorLayout>
CodePudding user response:
This is because you hard set android:layout_marginTop="545dp"
. Try never to do that. Also i think use costaint layour in youre case is better. Just change <androidx.coordinatorlayout.widget.CoordinatorLayout>
inside nested scroll view to <androidx.constraintlayout.widget.ConstraintLayout>
and add this atributes:
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent
If you need to show nested view in fullscteen, just chaange android:layout_height="wrap_content"
to android:layout_height="match_parent"