2011-06-02 109 views
4

伙计。我有这样的代码(的AsyncTask)RotateAnimation无持续时间

我的动画()函数:

public void animation() 
     { 
     int currentRotation = 0; 
      anim = new RotateAnimation(currentRotation, (360*4), 
        Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,0.5f); 
      currentRotation = (currentRotation + 45) % 360; 
      anim.setInterpolator(new LinearInterpolator()); 
      anim.setDuration(4000);// i want rotating without this <------------------ 
      anim.setFillEnabled(true); 
      anim.setFillAfter(true); 
      refresh.startAnimation(anim); 
     } 

谁能告诉我这是可能做到这一点,而不anim.setDuration ???? 只是开始..当我按下按钮(例如)动画停止。 请帮帮我。 问候,彼得。

最终代码:

public void animation() 
      { 
      int currentRotation = 0; 
       anim = new RotateAnimation(currentRotation, (360*4), 
         Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,0.5f); 
       currentRotation = (currentRotation + 45) % 360; 
       anim.setInterpolator(new LinearInterpolator()); 
       anim.setDuration(4000); 
       // anim.setRepeatMode(Animation.INFINITE); 
       anim.setRepeatCount(Animation.INFINITE); 
       anim.setFillEnabled(true); 
       anim.setFillAfter(true); 
       refresh.startAnimation(anim); 
      } 

和地方refresh.clearAnimation();为停止动画 这对我的工作完美..如果这里有些东西错了 - 请告诉我..总之谢谢你的答案:)

回答

9

我认为你应该看重复模式。持续时间是一个循环播放动画的时间,如果您将其设置为在此之后重复播放,则可以永久播放。见thisthat

例如,你可以使用:

anim.setRepeatCount(Animation.INFINITE); 
anim.setRepeatMode(Animation.RESTART); 
+0

谢谢你,老兄。这非常有帮助 – Peter 2011-06-02 13:58:00

0

由于PearsonArtPhoto建议,你应该看看重复模式。持续时间是一个循环播放动画的时间,如果您将其设置为在此之后重复播放,则可以永久播放。

使用ObjectAnimator来实现结果。 例如,您可以使用:

anim.setRepeatCount(Animation.INFINITE); 
anim.setRepeatMode(ValueAnimator.RESTART); //note the difference here