暂停和恢复洛蒂动画
我正在实施洛蒂动画,整个动画效果很好! 但是,我想添加一些代码,将暂停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() } }
任何意见将不胜感激!
- 如何注入瞬间依赖工厂与Kodein?
- 如何在Android中创建一个文件的副本?
- getExternalFilesDir返回不一致的目录
- 通过kotlin传递的parcelable数组正在发射最后一个项目
- Android体系结构组件房间ViewModel CompleteableFormAction
你可以做的是使用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 } } } }
希望它有帮助。
- CWAC相机自动对焦()和闪光灯模式的问题
- 我的输入不被识别
- RxJava 1.x .zip()不适用于RxJava 2.0
- Kotlin – MainActivity扩展AppCompatActivity,onRequestPermissionsResult函数未找到,不能被覆盖
- 调用File.createNewFile()时,权限被拒绝 Android的
- kotlin android – Xposed IllegalArgumentException'android.content.res.CoollifeUITpedArray'
- 无法获取Meetup API访问令牌与改造 – Android
- Kotlin与地图(标记不显示)
- Kotlin从Factory方法返回相同的对象