kotlin - 如何在 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())
}
解决方案
推荐阅读
- scala - Pyspark 到 Spark-scala 的转换
- excel - 使用选项保护 Office 脚本中的工作表
- python - ROS - 使用自定义 ROS 消息编写包文件时出现序列化错误
- c++ - CUDA如何从屏幕获取像素?
- android - 如何在flutter中使用table_calendar获取一个月内的所有事件?
- excel - Excel 导出经典 Ap 前导零
- java - 使用参数化参数调用方法
- netsuite - 如何使用 suitescript 2.0 在 Netsuite 中设置时间?
- animation - 在 SwiftUI 中将视图添加到层次结构时如何动画过渡
- mysql - 通过计算另一个表中的值来更新和设置列行值