Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop an ValueAnimator without Listener.onAnimationEnd called

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?

like image 378
L. Swifter Avatar asked Jan 18 '16 05:01

L. Swifter


2 Answers

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();
like image 60
saleh gholamian Avatar answered Nov 05 '22 06:11

saleh gholamian


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.

like image 9
CommonsWare Avatar answered Nov 05 '22 05:11

CommonsWare