MotionLayout-一个过渡禁用另一个过渡



我在一个MotionScene中有两个转换:

<Transition
android:id="@+id/swipeRightTransition"
app:constraintSetEnd="@id/swipedRight"
app:constraintSetStart="@+id/defaultPosition" >
<OnSwipe
app:maxAcceleration="60"
app:dragDirection="dragRight"
app:onTouchUp="autoComplete"
app:touchAnchorId="@id/pieChart"
app:touchAnchorSide="right"/>
</Transition>
<Transition
android:id="@+id/swipeLeftTransition"
app:constraintSetEnd="@id/swipedLeft"
app:constraintSetStart="@+id/defaultPosition" >
<OnSwipe
app:maxAcceleration="60"
app:dragDirection="dragLeft"
app:onTouchUp="autoComplete"
app:touchAnchorId="@id/pieChart"
app:touchAnchorSide="left"/>
</Transition>

如果禁用第一个转换"0";滑动右过渡";使用getTransition(R.id.swipeRightTransition(.setEnable(false(,第二个也将被禁用!并且设置";setEnable(true(";到第二个没有效果,它无论如何都会被禁用。如果您将禁用第二个transtion";swipeLeftTransition";第一个过渡运行良好。我一点也不明白。

全场景代码:

<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ConstraintSet android:id="@+id/defaultPosition">
<Constraint android:id="@+id/pieChart"
android:layout_width="0dp"
android:layout_height="220dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@id/leftArrowLayout"
app:layout_constraintEnd_toStartOf="@id/rightArrowLayout"
app:layout_constraintTop_toTopOf="parent"
android:layout_gravity="center"/>
</ConstraintSet>
<ConstraintSet android:id="@+id/swipedLeft">
<Constraint android:id="@+id/pieChart"
android:layout_width="220dp"
android:layout_height="220dp"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</ConstraintSet>
<ConstraintSet android:id="@+id/swipedRight">
<Constraint android:id="@+id/pieChart"
android:layout_width="220dp"
android:layout_height="220dp"
app:layout_constraintStart_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</ConstraintSet>
<Transition
android:id="@+id/swipeRightTransition"
app:constraintSetEnd="@id/swipedRight"
app:constraintSetStart="@+id/defaultPosition" >
<OnSwipe
app:maxAcceleration="60"
app:dragDirection="dragRight"
app:onTouchUp="autoComplete"
app:touchAnchorId="@id/pieChart"
app:touchAnchorSide="right"/>
</Transition>
<Transition
android:id="@+id/swipeLeftTransition"
app:constraintSetEnd="@id/swipedLeft"
app:constraintSetStart="@+id/defaultPosition" >
<OnSwipe
app:maxAcceleration="60"
app:dragDirection="dragLeft"
app:onTouchUp="autoComplete"
app:touchAnchorId="@id/pieChart"
app:touchAnchorSide="left"/>
</Transition>
</MotionScene>

请帮忙!

这是一个bug/特性。

第一个过渡是默认过渡。所以在开始的时候,你是在过渡。它被禁用了。因此,它无法切换到另一个转换,因为您被困在一个禁用的转换上。简单的解决方案是同时设置另一个转换。

所以:

ml.setTransition(R.id.swipeLeftTransition);
ml.getTransition(R.id.swipeRightTransition).setEnable(false)

测试:

<?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
android:id="@+id/sLeft"
motion:constraintSetStart="@+id/start"
motion:constraintSetEnd="@+id/left">
<OnSwipe
motion:touchAnchorId="@id/view"
motion:dragDirection="dragLeft" />
</Transition>
<Transition
android:id="@+id/sRight"
motion:constraintSetStart="@+id/start"
motion:constraintSetEnd="@+id/right">
<OnSwipe
motion:touchAnchorId="@id/view"
motion:dragDirection="dragRight" />
</Transition>
<ConstraintSet android:id="@+id/start">
</ConstraintSet>
<ConstraintSet android:id="@+id/left">
<Constraint
android:id="@+id/view"
android:layout_width="64dp"
android:layout_height="64dp"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintLeft_toLeftOf="parent"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintBottom_toBottomOf="parent"/>
</ConstraintSet>
<ConstraintSet android:id="@+id/right">
<Constraint
android:id="@+id/view"
android:layout_width="64dp"
android:layout_height="64dp"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintRight_toRightOf="parent"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintBottom_toBottomOf="parent"/>
</ConstraintSet>

如果我打电话给

onAttachedToWindow() {
super.onAttachedToWindow();

motionLayout.setTransition(R.id.sRight);
motionLayout.getTransition(R.id.sLeft).setEnable(false);
}

我只能向右滑动

唯一的另一个问题是;"左";你被卡住了

相关内容

最新更新