首页 > 解决方案 > 如何在 SharedElementTransition 中使用 LottieAnimationView?

问题描述

我决定使用 Lottie 动画从活动切换到活动。我的动画覆盖了整个屏幕,我希望在第一个活动上播放一半的动画时间,在第二个活动上播放其余时间

我尝试使用共享元素转换,但它不能正常工作,因为当新活动开始时,我首先看到的是新活动,然后在几毫秒后 Lottie 动画恢复。我想避免在 Lottie 动画结束之前显示新活动

第一个活动 XML 文件

<RelativeLayout android:layout_width="match_parent"
                android:layout_height="match_parent"
                xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res-auto">

    <com.airbnb.lottie.LottieAnimationView android:layout_width="match_parent"
                                           android:layout_height="match_parent"
                                           android:id="@+id/newActivityAnimation"
                                           app:lottie_fileName="transitionAnimation.json"
                                           android:scaleType="centerCrop"
                                           android:elevation="5dp"
                                           android:transitionName="sharedNewActivityTransition"

    />

第二个活动 XML 文件

<RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".ui.MenuActivity">

    <com.airbnb.lottie.LottieAnimationView android:layout_width="match_parent"
                                           android:layout_height="match_parent"
                                           app:lottie_fileName="transitionAnimation.json"
                                           android:scaleType="centerCrop"
                                           android:id="@+id/changeActivityAnimationMenu"
                                           android:elevation="5dp"
                                           android:transitionName="sharedNewActivityTransition"

    />

</RelativeLayout>

这是开始改变活动的功能

   override fun onLanguageClickListener(position: Int) {
        animateCollapseMenuSlide(isMenuCollapsed)
        newActivityAnimation.setMaxFrame(19)
        delay.delayedFunction({newActivityAnimation.playAnimation()},200)
        delay.delayedFunction({changeActivity()},1000)


    }


.
.
.


 private fun changeActivity() {
        val intent = Intent(this,MenuActivity::class.java)
        intent.flags = Intent.FLAG_ACTIVITY_NO_ANIMATION
        val options = ActivityOptionsCompat.makeSceneTransitionAnimation(this,activityTransitionAnimation,
            "sharedNewActivityTransition")
        startActivity(intent,options.toBundle())
    }

标签: kotlin

解决方案


推荐阅读