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

來源:互聯網
上載者:User

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

今日,在學習AnimatorSet時,使用play、with、after、before時,代碼書寫如下:

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();

運行代碼時,報錯,錯誤報表如下:

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)

然後,我將set.play(animator1).after(animator2).before(animator3).with(animator2);代碼修改為set.play(animator1);這時並不會報錯,我依次添加動畫,當添加到set.play(animator1).after(animator2).before(animator3).with(animator2);時,才會報錯,所以是最後一個with(animator2)有問題,然後,我又添加了一個動畫

ObjectAnimator animator4 = ObjectAnimator.ofFloat(v,"scaleY",1f,0f,1f);

將set.play(animator1).after(animator2).before(animator3).with(animator2);修改為

set.play(animator1).after(animator2).before(animator3).with(animator4);

代碼就不會報錯了。

所以,得到的結論是:

AnimatorSet的play、with、before、after函數不可複用同一個Animator,如果需要使用同樣的Animator,可以建立多個相同動畫的Animator,然後分別使用這多個動畫即可。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.