0

I have made an animation using AnimationDrawable with images.It is running well. But I want to stop it after 2 repeat. How can I do this? Here is my codes.

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);

    imageViewCark.setBackgroundResource(R.drawable.anim);
    animation = (AnimationDrawable) imageViewCark.getBackground();

    if(hasFocus == true){
        animation.start();

    }else{
        imageViewCark.setVisibility(ImageView.VISIBLE);
        animation.stop();
    }

}
emreturka
  • 846
  • 3
  • 18
  • 44

1 Answers1

0

Set an AnimationListener and in the onAnimationRepeat method you'll have to update a counter like counter++. When counter == 2 stop it!

Sorry mate, thought you used Animation. Check out this thread Android AnimationDrawable and knowing when animation ends.

By getting the current frame you can know when a repeat has went through, there is some code there for your problem.

Community
  • 1
  • 1
Carnal
  • 21,744
  • 6
  • 60
  • 75
  • I have implemented AnimationListener class and overrieded the methods. AnimationDrawable type is not suitible for this class. – emreturka Oct 30 '13 at 09:15
  • What do you mean "is not suitible for this class", you stop the animation that you use in the overriden method. Add some code! – Carnal Oct 30 '13 at 09:17
  • I have add some codes. How can I use AnimationListener with AnimationDrawable? – emreturka Oct 30 '13 at 09:24
  • Alright, sorry mate. I misunderstood you, check my updated answer. – Carnal Oct 30 '13 at 09:27