Skip to content Skip to sidebar Skip to footer

Starting And Stopping Animation

I am trying to figure out how on earth i can start and stop animation in my Android App. @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanc

Solution 1:

You have to apply the animation to a View. So assuming firstImage() is the animation you want to animate, call firstImage.startAnimation(frameAnimation). Then to end it call firstImage.clearAnimation().

EDIT:

Ok. Now that I see what you're doing, I'm guessing the Runnable you're using is never being called. What you can try is wait until the view has been fully inflated and start the animation in that. Something like this:

firstImage = (ImageView) findViewById(R.id.imageView1);
finalAnimationDrawableframeAnimation= (AnimationDrawable) firstImage.getBackground();
ViewTreeObservertreeObserver= firstImage.getViewTreeObsver();
treeObvserver.addOnGlobalLayoutListener(newOnGlobalLayoutListener(){
   @OverridepublicvoidonGlobalLayout(){
      frameAnimation.start();
   }
}

Now, I haven't tried this, but what I'm thinking will happen is when the view is fully inflated and visible, the animation will start.

Side-note: It's also a handy way to figure out when the views have their dimensions.

Post a Comment for "Starting And Stopping Animation"