Hi guys, still reminiscing about my scriptshit project, so at that time I was still a newbie, so to make an animated background, what came to my mind at that time was to just paste a *GIF image, OMG I was really shallow at that time, and it turned out to be true, the result FAILED!
Yup, it doesn't mean that when I failed to apply the gif animation above, then I just left it, NO NO NO, there are still many paths to dreams. Because at that time I was familiar with photoshop, so I used the application to extract the gif image above into pieces of images that represent the movement of the animation.
Next, I just implement it into my Android project, of course with the real rules, not a shallow way of just putting gifs. Okay, here I show you how.
As per the official Android documentation on animation drawables , Android does not support GIFs. As a workaround, Android offers Animation List / AnimationDrawable , so you need to convert the GIF to individual frames [.png files], as I did .
Next, name the file according to the frame order, for example frame01.png, frame02.png, etc. Next, create an XML file for the animation list, say background_animation.xml, define it as below, then save and put it in the drawables folder.
<animation-list android:id="@+id/selected" android:oneshot="false">
<item android:drawable="@drawable/frame01" android:duration="50" />
<item android:drawable="@drawable/frame02" android:duration="50" />
<item android:drawable="@drawable/frame03" android:duration="50" />
....
<item android:drawable="@drawable/frameN" android:duration="50" />
To start an animation, you need to cast the image to an AnimationDrawable, and run it by calling start(), as shown below.
AnimationDrawable progressAnimation = (AnimationDrawable) yourImageView.getBackground();
progressAnimation.start();
Okay done, please compile and see the results!