It is not convenient to display GIF images on Android. Although some controls can be implemented, the effect is not very good. It is safe to use frame animation for processing.
① Define animation-list in XML:
<? XML version = "1.0" encoding = "UTF-8"?>
<Animation-list xmlns: Android = "http://schemas.android.com/apk/res/android" Android: oneshot = "false">
<Item Android: drawable = "@ drawable/F_1" Android: Duration = "30"/>
<Item Android: drawable = "@ drawable/F_2" Android: Duration = "30"/>
<Item Android: drawable = "@ drawable/F_3" Android: Duration = "30"/>
<Item Android: drawable = "@ drawable/F_4" Android: Duration = "30"/>
</Animation-List>
② Define the imageview in the XML layout and specify its SRC or background attribute as "@ anim/loading"
③ In Java code:
Imageview = (imageview) findviewbyid (R. Id. Frame );
Animationdrawable drawable = (animationdrawable) imageview. getdrawable ();
// When using the background attribute
// Animationdrawable drawable = (animationdrawable) imageview. getbackground ();
Drawable. setoneshot (false); // Replay
④ Called in Java code:
Drawable. Start () or drawable. Stop () to play and stop an animation.
Display GIF animation (Frame Animation playback)