Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a TranslateAnimation on my class. The animation starts automatically.

I set button that if it is clicked, the animation will be canceled (animation.cancel();).

I also set an AnimationListener for my class. If my animation ends, I will start a new Activity (you go to the menu).

public void onAnimationEnd(Animation animation) {
    startActivity(new Intent(Class.this, Class2.class));
}

My app is relying on that the user has to click the button before the animation ends. The problem is that animation.cancel(); is admitted as the end of the animation.

How to cancel the animation in the other way that was not counted as the end of the animation? Is that possible?

Thanks in advance!

like image 724
Ganjira Avatar asked Mar 03 '13 18:03

Ganjira


People also ask

How to Cancel animation in javascript?

cancel() The Web Animations API's cancel() method of the Animation interface clears all KeyframeEffect s caused by this animation and aborts its playback. Note: When an animation is cancelled, its startTime and currentTime are set to null .

How do I turn off animations on Android?

Open Settings . Scroll down and select Accessibility. Scroll down to Display and tap Text and display. Tap the toggle switch for Remove animations to turn it on.


1 Answers

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

@Override
public void onAnimationCancel(Animator animation) {
  animation.removeAllListeners();
}
like image 184
Simas Avatar answered Sep 24 '22 00:09

Simas