在加载我的Lottie的JSON之后未显示的图像在Surfach Holder中可以亮点
我有一个Lottie JSON文件,在SurfaceView的LottiedRawable中加载后,我会用ValueAnimator播放它。但是图像没有显示,动画在没有图像的情况下运行!
但是,当我在Lottieanimationview中测试了这个JSON时,它的工作正常。那么我该怎么做才能在Lottiedrawable中玩? Thx
Lottiedrawable,播放没有图像显示:
if (lottieDrawable.composition == null) {
//val url = "https://assets4.lottiefiles.com/packages/lf20_dkzdaf1z.json"
//val task = LottieCompositionFactory.fromUrl(applicationContext, url)
val input = applicationContext.assets.open("wallpaper_lottie.json")
val task = LottieCompositionFactory.fromJsonInputStream(input, null)
//val input = applicationContext.assets.open("wallpaper_lottie.zip")
//val zip = ZipInputStream(input)
//val task = LottieCompositionFactory.fromZipStream(zip, null)
task.addFailureListener {
Log.i(TAG, "LOT::addFailureListener, " + it.message)
}
task.addListener { comp ->
// lottie drawable
lottieDrawable.composition = comp
Log.i(TAG, "LOT::lottieDrawable.composition, 1 = ${lottieDrawable.composition.toString().subSequence(0, 15)}")
val lotDrawableWidth = (screenWidth * 90F / 100F).toInt()
val lotDrawableHeight = (screenWidth * 80F / 100F).toInt()
val statusBarHeight = 65
val lotDrawableLeft = ((screenWidth - lotDrawableWidth) / 2).toInt()
val lotDrawableTop = (screenHeight - statusBarHeight).toInt()
lottieDrawable.bounds = Rect(
lotDrawableLeft,
lotDrawableTop,
lotDrawableLeft + lotDrawableWidth,
lotDrawableTop + lotDrawableHeight,
)
// lottie animator
lottieAnimator.cancel()
lottieAnimator.setIntValues(0, lottieDrawable.maxFrame.toInt())
lottieAnimator.repeatCount = LottieDrawable.INFINITE
lottieAnimator.duration = 6000
lottieAnimator.addUpdateListener { anim ->
val frame = anim.animatedValue as Int
lottieDrawable.frame = frame
// lottieDrawable.draw(canvas)
Log.i(TAG, "LOT::addUpdateListener, frame = ${lottieDrawable.frame}")
}
lottieAnimator.start()
}
}
Lottieanimationview,播放图像显示:
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/iv_scanning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
app:lottie_fileName="wallpaper_lottie.json"
app:lottie_loop="true"
/>
I have a Lottie json file, I play it with ValueAnimator after loaded in SurfaceView's LottieDrawable. But images are not showing, the animation is running without images!
But when I tested this json in LottieAnimationView, It just works fine. So what should I do to play in LottieDrawable? thx
LottieDrawable, play without images showing:
if (lottieDrawable.composition == null) {
//val url = "https://assets4.lottiefiles.com/packages/lf20_dkzdaf1z.json"
//val task = LottieCompositionFactory.fromUrl(applicationContext, url)
val input = applicationContext.assets.open("wallpaper_lottie.json")
val task = LottieCompositionFactory.fromJsonInputStream(input, null)
//val input = applicationContext.assets.open("wallpaper_lottie.zip")
//val zip = ZipInputStream(input)
//val task = LottieCompositionFactory.fromZipStream(zip, null)
task.addFailureListener {
Log.i(TAG, "LOT::addFailureListener, " + it.message)
}
task.addListener { comp ->
// lottie drawable
lottieDrawable.composition = comp
Log.i(TAG, "LOT::lottieDrawable.composition, 1 = ${lottieDrawable.composition.toString().subSequence(0, 15)}")
val lotDrawableWidth = (screenWidth * 90F / 100F).toInt()
val lotDrawableHeight = (screenWidth * 80F / 100F).toInt()
val statusBarHeight = 65
val lotDrawableLeft = ((screenWidth - lotDrawableWidth) / 2).toInt()
val lotDrawableTop = (screenHeight - statusBarHeight).toInt()
lottieDrawable.bounds = Rect(
lotDrawableLeft,
lotDrawableTop,
lotDrawableLeft + lotDrawableWidth,
lotDrawableTop + lotDrawableHeight,
)
// lottie animator
lottieAnimator.cancel()
lottieAnimator.setIntValues(0, lottieDrawable.maxFrame.toInt())
lottieAnimator.repeatCount = LottieDrawable.INFINITE
lottieAnimator.duration = 6000
lottieAnimator.addUpdateListener { anim ->
val frame = anim.animatedValue as Int
lottieDrawable.frame = frame
// lottieDrawable.draw(canvas)
Log.i(TAG, "LOT::addUpdateListener, frame = ${lottieDrawable.frame}")
}
lottieAnimator.start()
}
}
LottieAnimationView, play with image showed:
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/iv_scanning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
app:lottie_fileName="wallpaper_lottie.json"
app:lottie_loop="true"
/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最终,我使用ValueAnimator播放它,Fakeanimview做到了这一点。希望提供帮助:
Finally I play it using ValueAnimator, and FakeAnimView did the trick. Wish to help: