RotateAnimation without duration

guys. I have this code (asyncTask)

my animation ():

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

Can someone tell me that this is possible to do without anim.setDuration ???? just start .. and when I clicked on a button (for example), the animation stopped. Please help me. Regards, Peter.

final code:

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

and somewhere refresh.clearAnimation(); to stop the animation, it works perfect for me .. if something is wrong here, please tell me. Anyway, thanks for the answers :)

+4
source share
2 answers

I think you should look at the snooze mode. Duration is the time for one cycle through the animation, if you set it to repeat after that, then it can go on forever. See this and which .

For example, you can use:

 anim.setRepeatCount(Animation.INFINITE); anim.setRepeatMode(Animation.RESTART); 
+9
source

As suggested by PearsonArtPhoto, you should look at snooze mode. Duration is the time for one loop through the animation, if you set it to repeat after that, then it can go on forever.

Use ObjectAnimator to achieve the result. For example, you can use:

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

All Articles