我有一组动画,我发现每个片段启动时速度都很快,如何调整执行速度?
我尝试了这个,但动画太快了
val animator1 = ObjectAnimator
.ofFloat(binding.logoAnimated,
"translationX", 0f, -(width - point.x)).apply {
repeatCount = 1
repeatMode = ValueAnimator.REVERSE
}
val animator2 = ObjectAnimator
.ofFloat(binding.logoAnimated,"translationX",
0f, +(width - point.x)).apply {
repeatCount = 1
repeatMode = ValueAnimator.REVERSE
}
val animatorSet = AnimatorSet()
animatorSet.playSequentially(animator1, animator2)
animatorSet.start()
您可以通过ObjectAnimator调整动画的执行速度,您可以设置每个ObjectAnimator实例的
duration
属性。该属性决定动画需要多长时间才能完成(以毫秒为单位)
val duration = 2000L // 2000 milliseconds = 2 second
val animator1 = ObjectAnimator
.ofFloat(binding.logoAnimated, "translationX", 0f, -(width - point.x))
.apply {
this.duration = duration // Set duration for animator1
repeatCount = 1
repeatMode = ValueAnimator.REVERSE
}
val animator2 = ObjectAnimator
.ofFloat(binding.logoAnimated, "translationX", 0f, +(width - point.x))
.apply {
this.duration = duration // Set duration for animator2
repeatCount = 1
repeatMode = ValueAnimator.REVERSE
}
val animatorSet = AnimatorSet()
animatorSet.playSequentially(animator1, animator2)
animatorSet.start()