我正在尝试使用 alpha 和 motionLayout 制作淡入、淡出的效果,但它似乎不起作用。
这是我要淡出的 imageView。
<ImageView
android:id="@+id/tijeras"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:contentDescription="@string/tijeras"
android:src="@drawable/ic_tijeras" />
</android.support.constraint.motion.MotionLayout>
这是运动文件
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<Transition
app:duration="2000"
app:constraintSetStart="@+id/start"
app:constraintSetEnd="@+id/end">
<KeyFrameSet>
<KeyAttribute
app:framePosition="0"
app:motionTarget="@id/tijeras"
android:alpha="1.0"/>
<KeyAttribute
app:framePosition="50"
app:motionTarget="@id/tijeras"
android:alpha="0.0"/>
</KeyFrameSet>
</Transition>
<ConstraintSet android:id="@+id/start">
<Constraint android:id="@+id/tijeras"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="1.0"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/logo"/>
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint android:id="@+id/tijeras"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="1.0"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/logo"/>
</ConstraintSet>
</MotionScene>
我可以看到图像,但它没有做 alpha 输入和输出。任何想法?我需要触发它才能启动吗?