Ich habe ein einfaches MotionLayout erstellt, das fast einem Koordinatorlayout ähnelt (Animationen unterscheiden sich geringfügig).
So etwas hier:
Wenn Sie (ein paar) EditText-Ansichten im Inhaltsbereich verwenden, werden die MotionLayout-Animationen unterbrochen, sobald die Tastatur geöffnet wurde. Die Animationen haben jetzt eine Verzögerung, die Zustände sind falsch und die Benutzeroberfläche beginnt ein wenig einzufrieren. Irgendwelche Ideen, wie man das löst? Link zum Bug als GIF
Verwendete Versionen:
com.google.android.material:material:1.2.0-alpha01
androidx.constraintlayout:constraintlayout:2.0.0-beta3
Ich konnte das Verhalten auch in einer kleinen Beispiel-App reproduzieren
Beispiel 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>
android
android-motionlayout
LuckyMalaka
quelle
quelle
AppBarLayout
.Antworten:
Dieses Problem tritt häufig auf. Umhüllen Sie das Bewegungslayout mit einem ConstraintLayout
quelle