Is there a simple way to repeat a Android AnimatorSet
(infinite)? Can I set a AnimationListener
and restart the AnimatorSet
by calling
No, you can't repeat AnimatorSet, you can only repeat of a single ObjectAnimator/ ValueAnimator
But you can use PropertyValuesHolder, so that you can make an ObjectAnimator from a set of PropertyValuesHolder
here's example
val translateY = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, -100f, 100f)
val alpha = PropertyValuesHolder.ofFloat(View.ALPHA, 0.3f, 0.7f)
val scaleX = PropertyValuesHolder.ofFloat(View.SCALE_X, 0.8f, 1.2f)
val scaleY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 0.8f, 1.2f)
// and more
ObjectAnimator.ofPropertyValuesHolder(myView, translateY, alpha, scaleX, scaleY).apply {
interpolator = AccelerateDecelerateInterpolator()
// duration of each animation
duration = 500L
// repeat infinite count (you can put n times)
repeatCount = ValueAnimator.INFINITE
// reverse animation after finish
repeatMode = ValueAnimator.REVERSE
// start animation
start()
}