I create a gallery view where I download images from the Internet. While the images are loading, I want to display the animation as a placeholder for each image. I figured this could be done using AnimationDrawable, however the animation would not start. The first frame of the animation loads as expected, and if I use the same, for example, in onWindowFoucsChanged in action, everything works fine.
Inside the getView method of my GalleryItemCursorAdapter (which extends SimpleCursorAdapter) I have the following snippet:
AnimationDrawable frameAnimation = (AnimationDrawable) mContext.getResources().getDrawable(R.drawable.loading);
holder.picture.setImageDrawable(frameAnimation);
frameAnimation.setCallback(holder.picture);
frameAnimation.setVisible(true, true);
frameAnimation.start();
holder.picture is an ImageView. I get no errors, and the (very) similar code seems to work fine in other places, making me believe that this could be related to similar onCreate problems for animations being reported elsewhere. I also tried some variations of the above code.
My questions:
- Is there an easier / better way to display loading animations?
- What can I do to make the above example (if at all possible)?
source
share