[英]How to get total number of frames available in the Lottie Animation?
I'm using random Lottie animation in my android app.我在我的 android 应用程序中使用随机 Lottie 动画。 I need to know the total number of frames used in the Lottie animation.
我需要知道 Lottie 动画中使用的总帧数。 depending upon the total frames, I want to loop the animation from 1st frame to the certain frame.
根据总帧数,我想将动画从第一帧循环到特定帧。 for eg.
例如。 If the Lottie file contains 60 frames then I want to perform the animation from 1 to any number < 60.
如果 Lottie 文件包含 60 帧,那么我想执行从 1 到 <60 的任意数字的动画。
I'm using below dependency我正在使用以下依赖项
implementation 'com.airbnb.android:lottie:3.4.2'
You can see the first and last frame counts in the json file.您可以在 json 文件中看到第一帧和最后一帧的计数。 ip=first frame and op: last frame.
ip=第一帧和op:最后一帧。
Use addLottieOnCompositionLoadedListener
to get your lottie's Composition
.使用
addLottieOnCompositionLoadedListener
获取您的彩票的Composition
。
binding.myLottie.addLottieOnCompositionLoadedListener { composition ->
val startFrame = composition.startFrame
val endFrame = composition.endFrame
//will log start/end frame values
Log.d(TAG, "startFrame : $startFrame, endFrame : $endFrame")
}
Then to specific part of an animation use setMinAndMaxFrame()
然后到动画的特定部分使用
setMinAndMaxFrame()
binding.myLottie.addLottieOnCompositionLoadedListener { composition ->
val startFrame = composition.startFrame
val endFrame = composition.endFrame
if (maxFrame < endFrame) {
binding.myLottie.setMinAndMaxFrame(1, maxFrame)
}
}
read here more about looping a specific part of an animation.在这里阅读更多关于循环动画特定部分的信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.