11

Possible Duplicate:
Android: Animation Position Resets After Complete

I'm using RotateAnimation to rotate an ImageView. The code is simple:

this.button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Animation ani = new RotateAnimation(
                0, /* from degree*/
                30, /* to degree */
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        ani.setDuration(1000);
        imageView.startAnimation(ani);
    }
});

You can see I want the imageView rotate 30 degree.

It works, but when rotating is done, the image go back to the original state, the same position and degree before rotating. I want to fix ImageView at last Animation position i.e want to fix the image tilted by 30 degree. How to fix it?

Community
  • 1
  • 1
Freewind
  • 193,756
  • 157
  • 432
  • 708

2 Answers2

22

I just find an solution:

ani.setFillAfter(true);

It works :)

Freewind
  • 193,756
  • 157
  • 432
  • 708
0

It's the normal way when you use animation on Android.

You can:

  • start a new animation with no duration and repeat property on "infinite", and you rotate your image inside
  • Put the rotation value manually at the end of the animation (but you can't do that without specific animation below Android 3.0 if I'm not wrong).
Aerilys
  • 1,628
  • 1
  • 16
  • 22