Display GIF animation (Frame Animation playback)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.