开发者

RotateAnimation without duration

开发者 https://www.devze.com 2023-03-09 20:21 出处:网络
guys. i have this code (asyncTask) my animation() function : public void animation() { intcurrentRotation = 0;

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);
                currentRo开发者_JAVA百科tation = (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 :)


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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消