首页 > 解决方案 > MotionLayout 使用 Crossfade - altSrc 出现在 src 之上(原始图像不会消失)

问题描述

我正在使用 ImageFilterView,与 MotionScene 配合,在用户滑动时在图像之间切换(我也在向上移动图像)。

新图像确实出现了,但旧图像仍然存在。我可以在原始图像之上看到altSrc图像。

LogoWithOldAndNew

难道我做错了什么? 我的预期是否不正确,旧图像会淡出?

以下是相关代码:

布局.xml

<?xml version="1.0" encoding="utf-8"?>
<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:id="@+id/motionlayout_demo"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layoutDescription="@xml/the_scene_alt"
    app:showPaths="true"
    tools:context="com.designdemo.uaha.ui.MotionLayoutActivity">

...

    <androidx.constraintlayout.utils.widget.ImageFilterView
        android:id="@+id/nerd_text_img"
        android:src="@drawable/ic_nerderytxt_old"
        app:altSrc="@drawable/ic_nerderytxt_new"
        android:layout_width="450dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.43"/>

...

</androidx.constraintlayout.motion.widget.MotionLayout>

the_scene_alt.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">
        <OnSwipe
            motion:dragDirection="dragUp"
            motion:touchAnchorId="@id/text_the"
            motion:touchAnchorSide="right" />
    </Transition>

    <ConstraintSet android:id="@+id/start">
        <Constraint
            android:id="@+id/nerd_text_img"
            android:layout_width="450dp"
            android:layout_height="wrap_content"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintEnd_toEndOf="parent"
            motion:layout_constraintStart_toStartOf="parent"
            motion:layout_constraintTop_toTopOf="parent"
            motion:layout_constraintVertical_bias="0.43" >
            <CustomAttribute
                motion:attributeName="Crossfade"
                motion:customFloatValue="0" />
        </Constraint>        
    </ConstraintSet>

    <ConstraintSet android:id="@+id/end">   
        <Constraint
            android:id="@+id/nerd_text_img"
            android:layout_width="450dp"
            android:layout_height="wrap_content"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintEnd_toEndOf="parent"
            motion:layout_constraintStart_toStartOf="parent"
            motion:layout_constraintTop_toTopOf="parent"
            motion:layout_constraintVertical_bias="0.33" >
            <CustomAttribute
                motion:attributeName="Crossfade"
                motion:customFloatValue="1" />
        </Constraint>
    </ConstraintSet>

标签: androidandroid-appcompatandroid-constraintlayoutandroid-motionlayout

解决方案


使用标志:app:overlay="false"


推荐阅读