I have a problem with AnimationDrawable that I create programmatically, which starts as soon as I assign it to ImageView via imageView.setBackgroundDrawable (I support API 8).
This is the abbreviation of my code:
mSequence = new AnimationDrawable(); ImageView imageView = new ImageView(context); ImageView.setAdjustViewBounds(false);
All my resources are saved locally, so I add them to AnimationDrawable
for(String assetId : mAssets) { bitmap = loadBitmap(assetId); // returns a bitmap saved earlier if (bitmap != null) { mSequence.addFrame(new BitmapDrawable(res, bitmap), mFrameDuration); } }
And finally, I assign the AnimationDrawable view.
if (mSequence.getNumberOfFrames() > 0) { imageView.setBackgroundDrawable(mSequence); }
Now, before I can call the start() function, the animation starts as soon as the ImageView loads.
I want to be able to control when an animation starts according to my own logic.
Did this happen to anyone?
**
EDIT:
**
Thanks to Tom, I know that the reason for starting the animation is the change in visibility that happens with the ImageView , which actively happens after the AnimationDrawable assigned. The solution in my case is not trivial, since I have a difficult situation, but for others it can be easier.
EDIT 2:
I will return to setting drawable as a background according to the class description , and I will quote:
The easiest way to create frame animation is to define the animation in an XML file placed in the res / drawable / folder folder and set this as the background for the View object. Then call start () to start the animation.