I have an image view on which I apply a rotate animation. The animation works fine. On touch down, I attempt to stop the rotate animation using cancel(), resetting the animation using reset() and clearing the animation on the view using clearAnimation(). But the animation comes back to the original position. How to stop animation with the values it was when touch down event happens and restart from where it was stopped?
My animation is defined in the xml as below
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="360"
android:toDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="true"
android:fillEnabled="true"
android:duration="200000"
android:repeatMode="restart"
android:repeatCount="infinite"
android:interpolator="@android:anim/linear_interpolator"/>
I am attempting to stop the animation using the following code
private void stopAnimation(){
mRotateAntiClockwiseAnimation.cancel();
mRotateAntiClockwiseAnimation.reset();
imageView.clearAnimation();
mRotateAntiClockwiseAnimator.end();
mRotateAntiClockwiseAnimator.cancel();
stopAnimationForImageButton();
}
I am setting the animation on my view using the following code
mRotateAntiClockwiseAnimation = AnimationUtils.loadAnimation(context, R.anim.rotate_anticlockwise);
mRotateAntiClockwiseAnimation.setFillEnabled(true);
mRotateAntiClockwiseAnimation.setFillAfter(true);
imageView.setAnimation(mRotateAntiClockwiseAnimation);
mRotateAntiClockwiseAnimation.startNow();
imageView.invalidate();
As u see, even using cancel() or reset() did not help to stop the animation at the point where it was touched down. Any pointers would help