0

I am rotating an image to some degree using Rotation Animation .and in the same screen i want user to rotate the same image from the previous position to next by clicking a button.but nothing happen to rotation.

///inside oncreate 

RotateAnimation rotate = new RotateAnimation(0, rotateSpeed,
                        Animation.RELATIVE_TO_SELF, 0.9f,
                        Animation.RELATIVE_TO_SELF, 0.5f);

                rotate.setDuration(4000);
                rotate.setFillAfter(true);
                imv.setAnimation(rotate);

///inside button click

RotateAnimation rotate = new RotateAnimation(start, start+end,
                Animation.RELATIVE_TO_SELF, 0.9f,
                Animation.RELATIVE_TO_SELF, 0.5f);

        rotate.setDuration(2000);
        rotate.setFillAfter(true);
        imv.setAnimation(rotate);
SIK
  • 1
  • 5

3 Answers3

1

Pass your view and the value of rotation to this method. Hope this will solve your issue.

public void rotateView(final View v, final int rotation) {

    v.animate().setDuration(250).rotation(rotation).setListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            super.onAnimationStart(animation);
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            super.onAnimationCancel(animation);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
        }
    });
}
Syed Arsalan Kazmi
  • 949
  • 1
  • 11
  • 17
0
RotateAnimation rotate = new RotateAnimation(0, 360,
        Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
        0.5f);

rotate.setDuration(4000);
rotate.setRepeatCount(-1); // here you can set repeatcoount
yourView.setAnimation(rotate)

Hope it will help you.

Cheers!

KishuDroid
  • 5,411
  • 4
  • 30
  • 47
0

Oh,I just clear the Rotation Animation that was already applied before applying the new rotation animation.

view.clearAnimation();
SIK
  • 1
  • 5