Android loading animated gif

Disclaimer: This article is a blogger original article, shall not be reproduced without the consent of bloggers.

https://blog.csdn.net/jhg1204/article/details/24706059

Today, we want the application to load a page Loading gif animation, but do not know how to get on the Internet search, see a lot of people are using [email protected] written GifView.jar package.
So it is simple to understand a bit:
    looked under the author's source code, written in GifView inherits from View, then use the time it is very convenient, it can be used as a common UI components to use.
    When using a common UI components, for example, we generally use the following ways:   
<Button
        android:id="@+id/submit"
        android:layout_width="120dp"
        android:layout_height="60dp"
        android:text="@string/submitBtn"
/>
    For our own definition of UI controls. We use generally, for example, in the following manner:
    <package name of the class name.
        Attribute: value
        ...
    />
    Well, for such an approach, GifView certainly apply. To note are: the package name GifView where to write correctly. Otherwise you will GifView.jar after adding to your project, layout files certainly
will complain, package GifView class where the author wrote entitled: com.ant.liao but then we use the example of the following ways to write animated gif Components the layout of the document:  
<com.ant.liao.GifView
        android:id="@+id/gif"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
/>
    PS: property values need to configure their own.

    Completed the layout file, the next step is to carry out work on the load gif files (for example, the following code is added in the OnCreate):
    GF1 = (GifView) the findViewById (R.id.gif) ;
    // set Gif picture source
    gf1.setGifImage (R.drawable.gif);     
    size // set displayed, stretch or compress
    gf1.setShowDimension (400, 400);
    // set Loading mode: displaying Loading , loading side edge display, displays only the first frame is displayed again
    gf1.setGifImageType (GifImageType.COVER);

    the PS: Loading embodiment described:
    read of the source code. For loading mode is defined as:   
public enum GifImageType{
        /**
         * 在解码过程中,不显示图片,直到解码所有成功后。再显示
         */
        WAIT_FINISH (0),
        /**
         * 和解码过程同步,解码进行到哪里,图片显示到哪里
         */
        SYNC_DECODER (1),
        /**
         * 在解码过程中,仅仅显示第一帧图片
         */
        COVER (2);
        
        GifImageType(int i){
            nativeInt = i;
        }
        final int nativeInt;
    }
    In other words, the author offers three ways load, can be defined according to different needs of use.
    
    For animation display size setting, personally I think that is defective, a detailed set of numbers, may affect the quality of the animation. So in order to get the quality of the original animation. Able to obtain the size of the original animation disposed
opposite animation display areas:   
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.gif);
     width = bitmap.getWidth();
     height = bitmap.getHeight();
     gf1.setShowDimension(width, height);
    At this point, a gif animation had already finished loading!



Guess you like

Origin www.cnblogs.com/mqxnongmin/p/10929240.html