I have TextInputEditText inside a ConstraintLayout.
I use method doOnTextChange to change the right and bottom padding when text length is more that 20 symbols.
Unfortunately, it doesn't work as expected until I move to the next fragment and return back. The height of view didn't update after call updatePadding method.
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textField"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/text_size_medium"
android:layout_marginStart="@dimen/main_margin"
android:layout_marginEnd="@dimen/main_margin"
app:boxBackgroundMode="outline"
android:layout_marginBottom="9dp"
android:layout_marginTop="9dp"
app:boxStrokeColor="#d8d8d8"
app:boxStrokeWidth="0.5dp"
app:boxStrokeWidthFocused="1dp"
app:expandedHintEnabled="false"
app:boxBackgroundColor="@color/md_white_1000"
app:hintEnabled="false">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/textInputEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="5"
android:inputType="textMultiLine"
android:text="@={comment}"
android:textSize="@dimen/text_size_medium" />
</com.google.android.material.textfield.TextInputLayout>
Code to change the padding:
viewBinding.textInputEditText.doOnTextChanged { text, start, before, count ->
if (text?.length ?: 0 > 20){
viewBinding.textInputEditText.updatePadding(right = 16.toPx(), bottom = 50.toPx())
} else {
viewBinding.textInputEditText.updatePadding(right = 60.toPx(), bottom = 12.toPx(), top = 16.toPx())
}
}
How it works when screen starts:
And how it works after moving to next fragment and go back:

