Search code examples
androidrotateanimation

How to stop imageview any degree with rotateanimation on Android


I have a problem with rotate animation. I want my image to stop where I want as degree.I can stop it where I wanted but It goes to starting degree again..

Such as, it starts 0 degree and I wanted to stop it in 270 degree. Its ok but after halfsecond it goes to 0 degree again. I want it to fixed

                RotateAnimation r = new RotateAnimation(0.0f, 990.0f,0,bottle.getWidth()/2,0,bottle.getHeight()/2);
            r.setDuration((long) 2*500);
           r.setRepeatCount(0);

          bottle.startAnimation(r);

Solution

  • Have you looked into adding:

    r.setFillAfter(true);
    

    or

    r.setFillEnabled(true);
    

    If these don't work you, may need to rotate the image manually in the onAnimationEnd(), which I've done successfully with translateAnimation, but I have not tried it for a rotateAnimation.