13

I created a simple MotionLayout which is almost similar to a coordinator layout (animations are slightly different).
Something like this here:

enter image description here enter image description here

Using (a couple) EditText Views within the content area breaks the MotionLayout Animations once the Keyboard was open. The animations have now a delay, the states are wrong and the UI starts to freeze a bit. Any ideas how to solve this? Link to the bug as gif

Used Versions:

com.google.android.material:material:1.2.0-alpha01
androidx.constraintlayout:constraintlayout:2.0.0-beta3

I could reproduce the behavior also in a small sample app

Sample layout.xml:

<androidx.constraintlayout.motion.widget.MotionLayout 
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"
app:layoutDescription="@xml/animation"
tools:showPaths="true">

<androidx.appcompat.widget.Toolbar
    android:id="@+id/customtoolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.textview.MaterialTextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="32dp"
    android:layout_marginBottom="48dp"
    android:text="title"
    app:layout_constraintBottom_toTopOf="@+id/formLayout"
    app:layout_constraintStart_toStartOf="parent" />

<ImageView
    android:id="@+id/image"
    android:layout_width="200dp"
    android:background="#ff00ff"
    android:layout_height="200dp"
    android:scaleType="centerCrop"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@drawable/ic_home_black_24dp" />


<androidx.core.widget.NestedScrollView
    android:id="@+id/formLayout"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/image">

    <LinearLayout
        android:id="@+id/formLayoutContainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/container1"
            android:layout_width="match_parent"
            android:layout_height="200dp">

            <EditText
                android:id="@+id/container1EditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="EditText"
                android:importantForAutofill="no"
                android:inputType="text"
                android:lines="1" />
        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/container2"
            android:layout_width="match_parent"
            android:layout_height="200dp">

            <EditText
                android:id="@+id/container2EditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="EditText"
                android:importantForAutofill="no"
                android:inputType="text"
                android:lines="1" />
        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/container3"
            android:layout_width="match_parent"
            android:layout_height="200dp">

            <EditText
                android:id="@+id/container3EditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="EditText"
                android:importantForAutofill="no"
                android:inputType="text"
                android:lines="1" />
        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/container4"
            android:layout_width="match_parent"
            android:layout_height="200dp">

            <EditText
                android:id="@+id/container4EditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="EditText"
                android:importantForAutofill="no"
                android:inputType="text"
                android:lines="1" />
        </com.google.android.material.textfield.TextInputLayout>

        <com.google.android.material.button.MaterialButton
            android:id="@+id/saveButton"
            android:layout_width="120dp"
            android:layout_height="wrap_content"
            android:layout_gravity="end"
            android:layout_marginTop="24dp"
            android:layout_marginBottom="16dp"
            android:text="Save" />
    </LinearLayout>

</androidx.core.widget.NestedScrollView>

</androidx.constraintlayout.motion.widget.MotionLayout>

animation.xml:

<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<Transition
    app:constraintSetEnd="@id/end"
    app:constraintSetStart="@id/start"
    app:motionInterpolator="easeIn">

    <OnSwipe
        app:dragDirection="dragUp"
        app:touchAnchorId="@id/formLayout"
        app:touchAnchorSide="top" />

</Transition>

<ConstraintSet android:id="@+id/start">
    <Constraint
        android:id="@id/image"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:alpha="1"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Constraint
        android:id="@id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="32dp"
        android:layout_marginBottom="48dp"
        android:scaleX="1.0"
        android:scaleY="1.0"
        app:layout_constraintBottom_toTopOf="@+id/formLayout"
        app:layout_constraintStart_toStartOf="parent" />
</ConstraintSet>

<ConstraintSet android:id="@+id/end">
    <Constraint
        android:id="@id/image"
        android:layout_width="200dp"
        android:layout_height="72dp"
        android:alpha="0"
        android:translationY="-10dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Constraint
        android:id="@id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="55dp"
        android:scaleX="0.85"
        android:scaleY="0.85"
        app:layout_constraintBottom_toBottomOf="@id/customtoolbar"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@id/customtoolbar" />
</ConstraintSet>

<KeyFrameSet>
    <KeyPosition
        app:framePosition="70"
        app:keyPositionType="pathRelative"
        app:motionTarget="@id/title"
        app:percentY="0.1" />

    <KeyAttribute
        android:alpha="0.8"
        app:framePosition="60"
        app:motionTarget="@id/image" />

</KeyFrameSet>

</MotionScene>
0xPixelfrost
  • 10,244
  • 5
  • 39
  • 58
  • It's because of different scrolling event with/or without keyboard. For our case, we just disabling scrolling of `AppBarLayout`. – GensaGames Nov 11 '19 at 21:33
  • What is the value of _windowSoftInputMode_ in your manifest? When you scroll, it looks like the focused _EditText_ is being scrolled back into view which makes sense. It is not clear what you want to happen in this scenario. You can try changing the value of _windowSoftInputMode_ to see if it helps you at all. – Cheticamp Nov 15 '19 at 15:53
  • Do you mind putting your sample on github so we can help you analyze from there? – Isai Damier Nov 16 '19 at 17:42
  • @IsaiDamier https://github.com/CaptMustache/views-widgets-samples I just added an EditText Field to the end of the scolllayout. Please check the "Complex Motion Samples" and play around with the Inputfield + Keyboard + Scrolling – 0xPixelfrost Nov 20 '19 at 18:47
  • @GensaGames The approach here is to use only the motion layout and its animations without using the AppBarLayout. See Googles motion layout sample 17 +18 https://github.com/CaptMustache/views-widgets-samples/tree/master/ConstraintLayoutExamples/motionlayout/src/main/res/layout – 0xPixelfrost Nov 20 '19 at 18:55
  • @Cheticamp I tried them all already, without success. With a coordinator layout i could use android:windowSoftInputMode="adjustResize" to fix the animation with open keyboard, but the goal here is to use only the MotionLayout – 0xPixelfrost Nov 20 '19 at 19:00
  • I see you have a number of projects in that repo. Which one should I look at? – Isai Damier Nov 20 '19 at 19:09
  • Its the forked one from google views-widgets-samples:https://github.com/CaptMustache/views-widgets-samples – 0xPixelfrost Nov 21 '19 at 08:36
  • Did you find a solution to this? – frangulyan Apr 03 '20 at 12:09
  • Nope, i went back to the default CoordinatorLayout with a AppBarLayout + CollapsibleToolbar (incl. app:layoutDescription) for the header and a NestedScrollview + layout_behavior for the content. It worked out the some way but without the bugs above – 0xPixelfrost Apr 03 '20 at 15:07

1 Answers1

-2

This issue is common, wrapper the motion layout with a constraintLayout

<ConstraintLayout >

<androidx.constraintlayout.motion.widget.MotionLayout 
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"
app:layoutDescription="@xml/animation"
tools:showPaths="true">


<androidx.constraintlayout.motion.widget.MotionLayout />


<ConstraintLayout />
IceSoul
  • 24
  • 1
  • 1
  • 1
    I consumed one of my precious points to downvote this. What on earth answer is that, with no explanation and a solution that is bad and wouldn't work anyway. MotionLayout is designed to be the parent layout, it is designed to act just like a ConstraintLayout. Creating pointless layout indentation is just bad. – M'aiq the Coder Jun 26 '20 at 12:02
  • Works for me. ContraintLayout is designed to be the parent layout. – IceSoul Sep 01 '20 at 16:45