[英]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.