繁体   English   中英

如何获得 Lottie 动画中可用的总帧数?

[英]How to get total number of frames available in the Lottie Animation?

我在我的 android 应用程序中使用随机 Lottie 动画。 我需要知道 Lottie 动画中使用的总帧数。 根据总帧数,我想将动画从第一帧循环到特定帧。 例如。 如果 Lottie 文件包含 60 帧,那么我想执行从 1 到 <60 的任意数字的动画。

我正在使用以下依赖项

implementation 'com.airbnb.android:lottie:3.4.2'

您可以在 json 文件中看到第一帧和最后一帧的计数。 ip=第一帧和op:最后一帧。

示例图像

使用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") 
}

然后到动画的特定部分使用setMinAndMaxFrame()

binding.myLottie.addLottieOnCompositionLoadedListener { composition ->
    val startFrame = composition.startFrame
    val endFrame = composition.endFrame
    if (maxFrame < endFrame) {
        binding.myLottie.setMinAndMaxFrame(1, maxFrame)
    }
}

在这里阅读更多关于循环动画特定部分的信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM