Displaying Animated Gif Using Animate Drawable Problems
Solution 1:
Seems that I was experiencing the same problem, when I used whether it is setImageResource(R.drawable.load_animation)
or
setBackgroundResource(R.drawable.load_animation)
, the image wasn't displaying.
then I try to put the code in my XML view file, with android:background="@drawable/load_animation
got the image showed, but still not animated, it was only displaying a static image.
then after googling around a while I found that AnimationDrawable
can not work in onCreate
we can either put it in onResume
or onWindowsFocusChanged
. So here I try with this:
publicvoidonWindowFocusChanged(boolean hasFocus) {
loadingAnimation = (AnimationDrawable)
findViewById(R.id.img_loading).getBackground();
if (hasFocus) {
loadingAnimation.start();
}
else {
loadingAnimation.stop();
}
}
finally it works, the gif both showed and animated!
Solution 2:
Try calling setImageResource(R.drawable.load_animation)
, not setBackgroundResource(R.drawable.load_animation)
.
Solution 3:
i think you should use img.startxx(frameAnimation)
Post a Comment for "Displaying Animated Gif Using Animate Drawable Problems"