Android Loading GIF animation

Source: Internet
Author: User

Today, I want to load a GIF animation on the application's loading page, but I don't know how to do it, I searched the internet and saw many people are using [email protected] to write the Gifview.jar package,
So I got a quick look:
Read the author's source code, the written Gifview inherited from the view, then in the use of the time is very convenient, can be used as a normal UI components.
When working with normal UI components, we generally use the following methods:
<button        android:id= "@+id/submit"        android:layout_width= "120DP"        android:layout_height= "60DP"        android:text= "@string/submitbtn"/>
For our custom UI controls, we typically use the following approach:
< package name. Class Name
Property: Value
...
/>
Well, for this method, Gifview certainly also applies, need to note is: Gifview the package name to write correctly, otherwise you will gifview.jar add to your project, layout file certainly
will give an error, the author of the Gifview class contains the package name: Com.ant.liao then we will use the following way to write the GIF animation component layout file:
<com.ant.liao.gifview        android:id= "@+id/gif"        android:layout_width= "wrap_content"        android:layout_ height= "Wrap_content"        android:layout_gravity= "center"/>
PS: The desired property value is configured on its own.

The layout file is finished, and the next step is to load the GIF file (add the following code in OnCreate):
GF1 = (Gifview) Findviewbyid (r.id.gif);
Set up a GIF picture source
Gf1.setgifimage (r.drawable.gif);
Set the size of the display, stretch or compress
Gf1.setshowdimension (400, 400);
Set Load mode: First load, display, side load side display, show only first frame
Gf1.setgifimagetype (Gifimagetype.cover);

PS: Description of Loading mode:
Read the author's source code, for the loading method is defined as:
public enum gifimagetype{        /**         * In the decoding process, do not display the picture until the decoding is all successful, then display *        /wait_finish (0),        /**         * Synchronization with the decoding process, where the decoding goes, where the picture appears *        /Sync_decoder (1),        /** * During the         decoding process, only the first frame picture is displayed *        /COVER (2);                Gifimagetype (int i) {            nativeint = i;        }        final int nativeint;    }
That is, the author provides three ways to load, which can be defined according to different requirements when used.

For the animation display size settings, personal feel that the specific number to set, may affect the quality of the animation, so to get the original animation quality, you can get the original animation size to set
Display area of the animation:
Bitmap = Bitmapfactory.decoderesource (Getresources (), r.drawable.gif);     width = Bitmap.getwidth ();     Height = bitmap.getheight ();     Gf1.setshowdimension (width, height);
At this point, a GIF animation is loaded and finished!

Android Loading GIF animation

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.