如何连续启动AnimatorSet?

时间:2017-09-05 06:19:10

标签: android animation

我想在视图上运行多个AnimatorSet。 AnimatorSet应该一个接一个地连续运行。我想这样做而不使用处理程序延迟时间。我该怎么做?

1 个答案:

答案 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);

    play (Animator anim):  // add an animation and return AnimatorSet.Builder
    
  2. playSequentially(列出项目);

    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(收藏品);

    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