Repeating AnimatorSet Animation

I stayed for several hours, I feel like giving 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 several dozen combinations of startOffset , repeatCount and duration on the same objectAnimator s, but that is not the case.

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 once, the animation is repeated, and then onAnimationEnd no longer called.

Other similar questions include incorrect answers (referring to the android.view.animation structure) or suggest defining a custom interpolator for a single objectAnimator , but this is not quite what I'm looking for. Thanks.

+5
source share
3 answers

I had the same issue with AnimatorSet that played two animations together.

I created a set with animationSet.play(anim1).with(anim2) , which caused my animations to be repeated only once.

Changing it to animationSet.play(anim1).with(anim2).after(0) solved my problem and allowed the animation to loop indefinitely.

There seems to be a bug that forces you to have at least one consecutive step in the animation before the animations can be repeated several times.

+3
source

I meet the exact same situation. After almost a trial day, I suddenly suspect that the animator should be running in the 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 do not know why.

+2
source

You do not add a listener to your animation when you restart the animation as recursion. You need to create an AnimatorListenerAdapter object and reuse it.

I hope I guessed something for you!

0
source

Source: https://habr.com/ru/post/1213134/


All Articles