[英]Pause and Resume Lottie Animation
I'm implementing a Lottie animation and the entire animation works great!我正在实现一个 Lottie 动画,整个动画效果很好! However, I would like to add a bit of code that will pause the animation after 30 frames which I can then resume after a certain amount of time.
但是,我想添加一些代码,在 30 帧后暂停动画,然后我可以在一定时间后恢复。 Here is the code so far:
这是到目前为止的代码:
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()
}
}
What you can do is use progress from LottieAnimationView, threads and a flag, this will allow you to pause at a certain progress and resume exactly when you need to play your animation again 您可以做的是使用LottieAnimationView,线程和标志的进度 ,这将允许您暂停某个进度并在需要再次播放动画时完全恢复
I created the following example: 我创建了以下示例:
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
}
}
}
}
Hope it helps. 希望能帮助到你。
animationView.setMinAndMaxProgress(0.0f, 0.5f);//set 50% animation //lottie version 2.7.0
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
animationView.pauseAnimation();
}
}, 8000); // after 8s animation will pause/stop/cancel/resume.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.