Stop AnimatorSet of ObjectAnimators in Android

MajorDanger picture MajorDanger · Aug 25, 2014 · Viewed 20.5k times · Source

Im trying to stop the animation of an ImageView when a button is clicked. The animation I am using is an AnimatorSet consisting of 5 ObjectAnimators... The problem is that I can't figure how to stop and clear this animation from the ImageView when the button is clicked as btn.clearAnimation() obviously doesn't work.

Thank you for your help.

Answer

Libin picture Libin · Jan 16, 2015

If you had AnimatorSet listeners added, make sure you remove the listeners before cancel.

animatorSet.removeAllListeners();
animatorSet.end();
animatorSet.cancel();