I add an AnimatorListenerAdapter into an ValueAnimator, but i need to stop the ValueAnimator while it's running sometime.
I tried ValueAnimator.cancel() or ValueAnimator.stop(), they both can stop the animator, but the AnimatorListenerAdapter.onAnimationEnd() called which is I don't want.
ValueAnimator.pause() works but it's only above api 19, so i can't use it;
Is there anyway else I can do this?
Under certain circumstances, the use of the flag may cause problems.
You should using removeListener before call cancel method:
animator.removeAllListeners(); // Or animator.removeListener(your listener);
animator.cancel();
Use cancel() or stop(), along with a boolean field somewhere. The boolean serves as a flag to tell onAnimationEnd() whether or not it should do its regular work. Default that boolean to true; flip it to false when you want to block normal animation-end processing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With