How to cancel an animation, but not to end it? How to cancel an animation, but not to end it? android android

How to cancel an animation, but not to end it?


Once the animation is cancelled, you can remove the listener thus preventing onAnimationEnd from being called:

@Overridepublic void onAnimationCancel(Animator animation) {  animation.removeAllListeners();}


animation.cancel() is calling the animation listener as API documentation describes:

Cancelling an animation invokes the animation listener, if set, to notify the end of the animation. If you cancel an animation manually, you must call reset() before starting the animation again.

If you want different behaviour on cancel() and onAnimationEnd() i would suggest a boolean variable, which can be set on button click, and onanimationend checks whether it is true.