2

I'm creating an animation which should change randomly, so i needed to use AnimationDrawable (and yes, i couldn't manage that by using Animation.) So basicly, i have some imageviews and i am dynamically adding frame into, and setting to them. So far, everything works well. I can see that animation works, but the problem is after one animation has completed i need to remove every frame on that imageView and then add new ones to it. But unfortunately i couldn't find a way to remove frames... Is there a way to this? or it is just annoying lack?

Thanks in advance.

yahya
  • 4,810
  • 3
  • 41
  • 58

2 Answers2

1

Manage it by setting animationDrawable to null, recreating it and then setting it back to imageview... But not sure if this is a effective way to do this. I still think there should be a method something like removeFrame... Anyway here is solution:

AnimationDrawable animationFrame = (AnimationDrawable) view.getDrawable();
animationFrame = null;
animationFrame = new AnimationDrawable(); 
// Do stuff...
view.setBackgroundDrawable(animationFrame);

Please let me know if there is more effective way to handle this. Because creating a new object over and over again in miliseconds can cause memory issue i guess.

yahya
  • 4,810
  • 3
  • 41
  • 58
0

For me this worked:

animationView.setBackgroundResource(0);

Just set the BackgroundResource null for the corresponding ImageView

Chris8447
  • 306
  • 4
  • 7