Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check to see if animation is running before starting new animation?

I have a activity where I have multiple ImageViews and when you click on it the ImageView will fade out and fade back in. What I'm trying to figure out is how I can click one ImageView and start the animation and when I click a 2nd one and the animation is still running it will ignore the second one. I think I need to do something with the animationListener but I can't figure out how to use that to check if the animation is running or not before I initiate a new animation. I could have sworn I saw an example that did this but I've been looking for days and can't find it anymore, I'm hoping someone would be able to help out here..... below is the code for my animation:

// Create Animation protected void fadeAnimation() {     tempImg.startAnimation(fadeout);     //Allow animation to finish     mHandler.postDelayed(new Runnable() {         public void run() {         tempImg.startAnimation(fadein);         }     }, 1000); } 
like image 736
Chris D Avatar asked Mar 30 '12 03:03

Chris D


1 Answers

I'm assuming both fadeout and fadein are Animation objects.

Use fadeout.hasEnded() to check if the first has finished before starting your second one.

For more details about the Animation class, see here: http://developer.android.com/reference/android/view/animation/Animation.html

like image 70
Grimmace Avatar answered Oct 02 '22 22:10

Grimmace