0

I am trying to create an animation drawable that will simply have two frames and loop on the screen.

However, for some reason my Animationdrawable isn't doing even one round and just showing the first frame, Not to mention the looping...

Here is my code:

Handler handler = new Handler();
AnimationDrawable mouseani = new AnimationDrawable();
ImageView img;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Drawable mouse1 = getResources().getDrawable(R.drawable.mouse_for_use);
    Drawable mouse2 = getResources().getDrawable(R.drawable.mouse_for_use_2);
    mouseani.addFrame(mouse1, 500);
    mouseani.addFrame(mouse2, 500);
    img = (ImageView) findViewById(R.id.imgView);
    img.setBackgroundDrawable(mouseani);
    mouseani.setCallback(img);
    mouseani.setVisible(true, true);
    mouseani.start();
    mouseani.stop();
}

Thanks!

rel-s
  • 6,108
  • 11
  • 38
  • 50

1 Answers1

0

you cannot start and stop like you did one after another , the animation happens to be an aysnc process.

You will have to find another way , for example to create a listener for when the animationdrawable is out of frames , then re invoke the animation .

Take a look here for hints . Android AnimationDrawable and knowing when animation ends

Community
  • 1
  • 1
Muhammad Ahmed AbuTalib
  • 4,080
  • 4
  • 36
  • 59