I've been trying for hours, I feel it's time to give up. How can I loop an AnimatorSet defined in xml?
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator />
<objectAnimator />
<objectAnimator />
<objectAnimator />
</set>
I tried dozens of combinations of startOffset
, repeatCount
and duration
on the single objectAnimator
s, but that's just not the right way.
I read about this promising workaround:
a.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
animation.start();
Log.i();
}
});
but it just doesn't work: onAnimationEnd
is called one time, animation is repeated, and then onAnimationEnd
is not called anymore.
Other similar questions here involve wrong answers (referring to the android.view.animation
framework) or suggest defining a custom interpolator for a single objectAnimator
, but that's not really what I'm looking for. Thank you.
I had the same issue with an AnimatorSet
that played two animations together.
I created the set with animationSet.play(anim1).with(anim2)
, which resulted in my animations only repeating a single time.
Changing it to animationSet.play(anim1).with(anim2).after(0)
resolved my problem and allowed the animation to loop indefinitely.
It appears as though there is a bug that forces you to have at least one sequential step in the animation before animations can loop more than once.
I meet absolutely the same situation. After nearly trial of a day, I suddenly suspect that animator should be started on main thread. And it works.
mRandomPointAnimatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
Log.i(TAG, "onAnimationStart");
mRandomPointView.setVisibility(VISIBLE);
}
@Override
public void onAnimationEnd(Animator animation) {
Log.i(TAG, "onAnimationEnd");
mRandomPointView.setVisibility(INVISIBLE);
mHandler.post(new Runnable() {
@Override
public void run() {
if (isShown()) {
requestLayout();
mRandomPointAnimatorSet.start();
}
}
});
}
});
Current I don't know why.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With