Dedug of Android -- Circular dependencies cannot exist in AnimatorSet, circular
Today, when I was studying AnimatorSet and using play, with, after, and before, the code was written as follows:
ObjectAnimator animator1 = ObjectAnimator.ofFloat(v,"translationX",300f);ObjectAnimator animator2 = ObjectAnimator.ofFloat(v,"scaleX",1f,0f,1f);ObjectAnimator animator3 = ObjectAnimator.ofFloat(v,"scaleY",1f,0f,1f);AnimatorSet set = new AnimatorSet();set.setDuration(1000);set.play(animator1).after(animator2).before(animator3).with(animator2);set.start();
When running the code, an error is reported. The error report is as follows:
12-12 16:26:18.210 28528-28528/com.zhangmiao.animationdemo E/AndroidRuntime: FATAL EXCEPTION: main Process: com.zhangmiao.animationdemo, PID: 28528 java.lang.IllegalStateException: Circular dependencies cannot exist in AnimatorSet at android.animation.AnimatorSet.sortNodes(AnimatorSet.java:921) at android.animation.AnimatorSet.start(AnimatorSet.java:539) at com.zhangmiao.animationdemo.ObjectAnimatorDemo.onClick(ObjectAnimatorDemo.java:82) at android.view.View.performClick(View.java:4868) at android.view.View$PerformClick.run(View.java:20294) at android.os.Handler.handleCallback(Handler.java:815) at android.os.Handler.dispatchMessage(Handler.java:104) at android.os.Looper.loop(Looper.java:192) at android.app.ActivityThread.main(ActivityThread.java:5718) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:975) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)
Then, I set. play (animator1 ). after (animator2 ). before (animator3 ). with (animator2); the Code is modified to set. play (animator1); at this time, no error will be reported. I will add an animation in sequence and add it to set. play (animator1 ). after (animator2 ). before (animator3 ). with (animator2);, an error is reported, so there is a problem with the last with (animator2). Then, I added an animation.
ObjectAnimator animator4 = ObjectAnimator.ofFloat(v,"scaleY",1f,0f,1f);
Change set. play (animator1). after (animator2). before (animator3). with (animator2);
set.play(animator1).after(animator2).before(animator3).with(animator4);
The code will not report errors.
Therefore, we can conclude that:
The play, with, before, and after functions of the AnimatorSet cannot reuse the same Animator. To use the same Animator, you can create multiple animations of the same animation, then use the multiple animations.