2017-09-05 56 views
2

我想在視圖上運行多個AnimatorSet。 AnimatorSet應該連續運行。我想在不使用時間延遲處理程序的情況下執行此操作。我該怎麼做?如何連續啓動AnimatorSet?

+0

我試圖用,但有那個漫畫家集對象得到釋放異常。 –

+0

我有單獨的類來創建和運行動畫集。無論何時我需要創建或運行動畫設置,我都會使用它的實例。如果我連續調用運行AnimatorSet方法,它會發出異常。 –

+0

是的。我已經。 –

回答

2

在您的代碼中試試這個。

AnimatorSet bouncer = new AnimatorSet(); 
ObjectAnimator anim = ObjectAnimator.ofFloat(mTextView, "rotationX", 0f, 180f); 
anim.setDuration(2000); 
ObjectAnimator anim2 = ObjectAnimator.ofFloat(mTextView, "rotationX", 180f, 0f); 
anim2.setDuration(2000); 
ObjectAnimator anim3 = ObjectAnimator.ofFloat(mTextView, "rotationY", 0f, 180f); 
anim3.setDuration(2000); 
ObjectAnimator anim4 = ObjectAnimator.ofFloat(mTextView, "rotationY", 180f, 0f); 
anim4.setDuration(2000); 

bouncer.playSequentially(anim, anim2, anim3, anim4); 
bouncer.start(); 

方法:

  1. 播放(動畫阿尼姆);

    play (Animator anim): // add an animation and return AnimatorSet.Builder 
    
  2. playSequentially(List items);

    playSequentially (List items): // add a set of animations, play sequentially, and play them one by one 
    
  3. playSequentially(Animator ... Items);

    playSequentially (Animator... Items): // add a set of animations, play sequentially, and play them one by one 
    
  4. playTogether(Collection items);

    playTogether (Collection items): // add a set of animations, played sequentially, and played together 
    
  5. playTogether(Animator ... Items);

    playTogether (Animator... Items): // add a set of animations, play sequentially, and play together 
    
+0

這給我例外。 –

+0

將'mTextView'更改爲'View'。 – KeLiuyue

+0

請閱讀以上評論。謝謝btw。 :) –