【发布时间】:2020-10-16 11:18:32
【问题描述】:
我想在我的片段显示时自动启动动画。我已将autoTransition 属性设置为animateToEnd,但没有任何反应。
我目前正在使用 constraintLayout beta7。当降级到 beta6 或更低时,除了片段进入屏幕时动画完成之外,什么也没有发生。
我已经将一个 TransitionListener 附加到 MotionLayout 并观察到以下内容:
- 在 beta7 上 OnTransitionChange 被调用一次,进度值如此之低,我将其称为 0,永远不会调用 OnTransitionEnd 并且我的 TextView 保持不可见
- 在 beta6 或更低版本 OnTransitionChange 被调用两次,第一次的进度值相当随机,介于 0 和 0.5 之间,第二次是 1.0。之后,调用 OnTransitionEnd 并且我的 TextView 立即可见,那里没有动画。
这是 MotionScene xml 文件:
<?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="1000"
motion:motionInterpolator="easeInOut"
motion:autoTransition="animateToEnd">
</Transition>
<ConstraintSet android:id="@+id/start">
<Constraint android:id="@id/splash_head_TextView">
<Layout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="@id/topGuideLine"/>
<CustomAttribute
motion:attributeName="alpha"
motion:customFloatValue="0.0" />
</Constraint>
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint android:id="@id/splash_head_TextView">
<Layout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/splash_head"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="@id/topGuideLine"/>
<CustomAttribute
motion:attributeName="alpha"
motion:customFloatValue="1.0" />
</Constraint>
</ConstraintSet>
</MotionScene>
【问题讨论】:
-
有时使用 beta7 可以工作。 10 次中有 1 次。使用 beta 4 就可以了。
标签: android xml android-layout android-animation android-motionlayout