MotionLayout 使用 Crossfade - altSrc 出现在 src 之上(原始图像不会消失) [英] MotionLayout using Crossfade - altSrc appears on top of src (original image doesn't fade away)

查看:50
本文介绍了MotionLayout 使用 Crossfade - altSrc 出现在 src 之上(原始图像不会消失)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using an ImageFilterView, in coordination with a MotionScene, to switch between Images on user swipe (I am also moving the image up).

新图像确实出现了,但旧图像仍然存在.我可以在原始图像的顶部看到 altSrc 图像.

The new image does appear, but the old image remains. I can see the altSrc image on top of the original image.

我做错了吗?我的预期是否错误,旧图像会淡出?

相关代码如下:

layout.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>

推荐答案

使用标志:应用程序:覆盖=假"

Use the flag: app:overlay="false"

这篇关于MotionLayout 使用 Crossfade - altSrc 出现在 src 之上(原始图像不会消失)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆