Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RotateAnimation without duration

guys. i have this code (asyncTask)

my animation() function :

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 anyone tell me it's possible to do it without anim.setDuration ???? just only start .. and when i pressed on button(for example) animation stoped. 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(); for stop animation it's work perfect for me .. if here some thing wrong - please tell me .. Anyway thanks for the answers :)

like image 988
Peter Avatar asked Jun 02 '11 13:06

Peter


2 Answers

I think you should look at repeat mode. The duration is the time for one loop through the animation, if you set it up to repeat after that, then it can go on forever. See this and that.

For instance, you could use:

anim.setRepeatCount(Animation.INFINITE);
anim.setRepeatMode(Animation.RESTART);
like image 155
PearsonArtPhoto Avatar answered Sep 30 '22 20:09

PearsonArtPhoto


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

Use ObjectAnimator to achieve result. For instance, you could use:

anim.setRepeatCount(Animation.INFINITE);
anim.setRepeatMode(ValueAnimator.RESTART); //note the difference here
like image 36
Pradeep Kumar Kushwaha Avatar answered Sep 30 '22 19:09

Pradeep Kumar Kushwaha