I am trying to problematically add frames and duration to an AnimationDrawable but I cannot get the result I want. I can add the frames but subsequent calls do not clear the old frames. Is there a way to reset an AnimationDrawable?
Here is an excerpt from my code:
public void animate() {
if (a != null && a.isRunning()) {
a.stop();
}
//iv.setImageDrawable(null);
//iv.setBackgroundDrawable(null);
iv.setBackgroundResource(R.drawable.blank_animation);
a = (AnimationDrawable) iv.getBackground();
a.addFrame(res.getDrawable(R.drawable.blank), 1);
for (int i=0;i<Frames.size();i++) {
a.addFrame(res.getDrawable(Frames.get(i)), AnimationSpeed);
}
a.addFrame(res.getDrawable(R.drawable.blank), 1);
a.setOneShot(true);
a.start();
}
I have tried the following without success to clear either the ImageView and/or the AnimationDrawable.
iv.setImageDrawable(null);
iv.setBackgroundDrawable(null);
a = new AnimationDrawable();
iv.clearAnimation();
I have also tried to null the ImageView and recreate it and that did not reset the frames.
Any help would be greatly appreciated.
Try like that