我遇到了 MotionLayout 的问题。我创建了一个场景,当我使用一个 onClick 转换时它可以工作。但我需要有两个。
我想要做的是:单击视图中的按钮时,该视图将隐藏,而另一个视图将显示。这行得通。但是现在当我单击另一个视图中的按钮时,我想显示第一个视图,而第二个需要隐藏。
这种作品,唯一的问题是它没有通过过渡来做到这一点。它只是显示。
我的场景看起来像:
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motion="http://schemas.android.com/apk/res-auto">
<Transition
motion:constraintSetEnd="@+id/end"
motion:constraintSetStart="@+id/start"
motion:duration="2000"
motion:motionInterpolator="easeOut">
<OnClick
motion:clickAction="transitionToEnd"
motion:targetId="@+id/hide_menu" />
</Transition>
<Transition
motion:constraintSetEnd="@+id/end"
motion:constraintSetStart="@+id/start"
motion:duration="2000"
motion:motionInterpolator="easeInOut">
<OnClick
motion:clickAction="transitionToStart"
motion:targetId="@+id/quick_menu_show_menu" />
</Transition>
<ConstraintSet android:id="@+id/start">
<Constraint
android:id="@+id/sidebar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:translationX="0dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent" />
<Constraint
android:id="@+id/quick_menu"
android:layout_width="19dp"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:translationX="-70dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@+id/sidebar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:translationX="-70dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent" />
<Constraint
android:id="@+id/quick_menu"
android:layout_width="19dp"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:translationX="0dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>
</MotionScene>
希望任何人都可以提供帮助。
亲切的问候,
科尔斯滕