我决定使用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())
}