End of animation

I have a fadeout animation in the view (inside the fragment), and every time the animation happens, after it ends, the view is redrawn again. I found work around view.SetVisibility(View.GONE) . But he does not wait for the end of the animation. I would like to execute this setVisibility code only after the animation is complete. What is the best way to do this?

+69
android android-fragments android-animation
Sep 30 2018-11-11T00:
source share
4 answers

You can add an animation listener to your animation object, for example

 anim.setAnimationListener(new Animation.AnimationListener(){ @Override public void onAnimationStart(Animation arg0) { } @Override public void onAnimationRepeat(Animation arg0) { } @Override public void onAnimationEnd(Animation arg0) { } }); 
+135
Sep 30 2018-11-11T00:
source share

Functionally the same as the accepted answer, but in a more concise way:

  /* Add/Remove any animation parameter */ theView.animate().alpha(0).setDuration(2000).withEndAction(new Runnable() { @Override public void run() { theView.setVisibility(View.GONE); } }); 

Enjoy :)

+12
Sep 29 '16 at 8:35
source share

You can also achieve this using Animation.setFillAfter

+8
Sep 30 '11 at 9:00
source share

Just grab your animation object and add an animation listener to it. Here is a sample code:

 rotateAnimation.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation animation) { // TODO Auto-generated method stub } @Override public void onAnimationRepeat(Animation animation) { // TODO Auto-generated method stub } @Override public void onAnimationEnd(Animation animation) { // TODO Auto-generated method stub **// WRITE HERE WHATEVER YOU WANT ON THE COMPLETION OF THE ANIMATION** } }); 
+8
Jun 03 '13 at 5:32
source share



All Articles