Dedug of Android -- Circular dependencies cannot exist in AnimatorSet, circular

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.