结论:
- LottieAnimationView setAnimation在 2.*是同步加载的 json、图片资源, 3.*采用的异步加载。而且是强制的
- 采用LottieDrawable 配合ImageView, 可以自主选择 加载方式
代码
重点代码
LottieCompositionFactory.fromAssetSync
同步加载资源
private var mPetLottieDrawable = LottieDrawable()
fun init(rootView: View, callback: GuideCallback?) {
outerGuideCallback = callback
guideContainerView = rootView.findViewById(R.id.camera_guide_container)
guideText = rootView.findViewById(R.id.camera_guide_text)
mPetLottieDrawable.setImagesAssetsFolder("pic_camera_normal")
mPetLottieDrawable.repeatCount = 0
}
private fun updateViewAnimation(view: View, type: Int, context: Context) {
jsonMap[type]?.also {json ->
if (mPetLottieDrawable.isAnimating) {
mPetLottieDrawable.cancelAnimation()
}
mPetLottieDrawable.clearComposition()
LottieCompositionFactory.fromAssetSync(context, json).value?.let {composite ->
mPetLottieDrawable.composition = composite
mPetLottieDrawable.playAnimation();
view.visibility = View.VISIBLE
}
}
}