我正在实施Lottie动画,整个动画效果很好!但是,我想添加一些代码,这些代码将在30帧之后暂停动画,然后我可以在一定时间后恢复。这是迄今为止的代码
animationView.playAnimation(0, 30)
animationView.addAnimatorListener(object : Animator.AnimatorListener {
override fun onAnimationEnd(animation: Animator) {
if (isLoading == false) {
//Everything has loaded. Continue Animation
//This line has no effect. The animation does not continue
animationView.playAnimation(30, 60)
//Resuming the animation just makes the animation disappear
//animation.resume()
}
}
任何建议将不胜感激!
答案 0 :(得分:6)
你可以做的是使用LottieAnimationView中的进度,主题和标记,这样你就可以暂停一定的进度和恢复确切地说,当您需要再次播放动画时
我创建了以下示例:
animationView.playAnimation()
animationView.loop(false)
isAnimating = true // Setup your flag
thread {
while (isAnimating){ // Loop that checks the progress of your animation
if (animationView.progress >= 0.5f){// If animation reaches 50%
runOnUiThread {
animationView.pauseAnimation()// Pause Animation
}
Thread.sleep(5000) // Pause for 5 seconds
runOnUiThread {
animationView.playAnimation(0.5f,1f) // Resume your animation from 50% to 100%
}
isAnimating = false
}
if(animationView.progress >= 1f){ // If animation reaches 100% stop animation
runOnUiThread {
animationView.cancelAnimation()
isAnimating = false
}
}
}
}
希望它有所帮助。
答案 1 :(得分:0)
animationView.setMinAndMaxProgress(0.0f, 0.5f);//set 50% animation //lottie version 2.7.0