Using gif in android

Now many apps can watch gifs, but android native controls do not support gifs, so a third party is used. In fact, there is nothing to say about displaying gifs.
But there are always special cases. For example, when I encountered a company that asked me to process gifs in C language, android-gif-drawable was also written in C language. I thought there were too many files, so I went to the Internet to find another one written in C language.
This is only 6 files, the java layer code is directly discarded
In fact, using Glide can also display gif, but it is not very good, the playback speed will be huge if the gif is loaded too much
Let's talk about android-gif-drawable first, it's easy to use
<pl.droidsonroids.gif.GifImageView
android:id="@+id/gif_image_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/test3"
/>                    
java loading is also simple
try {
    GifImageView gifImageView = findViewById(R.id.gif_image_view);
    GifDrawable gifFromResource = new GifDrawable( getResources(), R.drawable.test4 );
    gifImageView.setImageDrawable(gifFromResource);
} catch (IOException e) {
    e.printStackTrace () ;
}
It also supports various loading methods, and I will not list them one by one.
GifDrawable can operate on gif, such as start(), stop(), etc. There are many descriptions of it on the Internet.
Let's talk about Glide loading gif
GlideApp.with(this).load(R.drawable.test4).into(imageview);
It is also very simple. GifDrawable is also used to operate gif, and GifDrawable can be obtained in this way.
GlideApp.with(this).load(R.drawable.test4).listener(new RequestListener<Drawable>() {
    @Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
        return false;
}        

    @Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {    
        GifDrawable gifDrawable = (GifDrawable) resource;
        return false;
    }
}).into(imageView);
That is, calling start() or stop()
If the application gif is used a lot, it is recommended to use android-gif-drawable. If not, Glide can also be used.
Finally, let's talk about AndLibNsgif, the efficiency is there, but the java code has too many bugs, it's just a simple transplant, but the c code has no bugs, it's no problem to use it, and it's also very powerful




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325805324&siteId=291194637
gif