Skip to content Skip to sidebar Skip to footer

Displaying Animated Gif Using Animate Drawable Problems

I'm attempting to have my animated gif animate on loop with the following code but I'm not having any luck... JAVA ImageView img = (ImageView)findViewById(R.id.load_img); img.setBa

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"