I want to display animated GIF images in my aplication. As I found out the hard way Android doesn't support animated GIF natively.
However it can display animations using AnimationDrawable:
Develop > Guides > Images & Graphics > Drawables Overview
The example uses animation saved as frames in application resources but what I need is to display animated gif directly.
My plan is to break animated GIF to frames and add each frame as drawable to AnimationDrawable.
Does anyone know how to extract frames from animated GIF and convert each of them into Drawable?
I had a really hard time to have animated gif working in Android. I only had following two working:
WebView works OK and really easy, but the problem is it makes the view loads slower and the app would be unresponsive for a second or so. I did not like that. So I have tried different approaches (DID NOT WORK):
I had some back and forth with
Ion
; Finally, I have it working, and it is really fast :-)Try this, bellow code display gif file in progressbar
loading_activity.xml(in Layout folder)
custom_loading.xml(in drawable folder)
here i put black_gif.gif(in drawable folder), you can put your own gif here
LoadingActivity.java(in res folder)
First of all the Android browser should support Animated GIFs. If it doesn't then it's a bug! Have a look at the issue trackers.
If you're displaying these animated GIFs outside of a browser it might be a different story. To do what you're asking would require external library that supports the decoding of Animated GIFs.
The first port of call would be to look at Java2D or JAI (Java Advanced Imaging) API, although I would be very surprised if Android Dalvik would support those libraries in your App.
For only android API (Android Pie)28 and +
use AnimatedImageDrawable asXML code, add a ImageView
AnimatedImageDrawable
is a child of Drawable and created byImageDecoder.decodeDrawable
ImageDecoder.decodeDrawable
which further required the instance ofImageDecoder.Source
created byImageDecoder.createSource
.ImageDecoder.createSource
can only take source as a name, ByteBuffer, File, resourceId, URI, ContentResolver to create source object and uses it to createAnimatedImageDrawable
asDrawable
(polymorphic call)Note: You can also create
Bitmap
using ImageDecoder#decodeBitmap.Output:
AnimatedDrawable also supports resizing, frame and color manipulation
Glide
Image Loader Library for Android, recommended by Google.
What that Glide has but Picasso doesn't
An ability to load GIF Animation to a simple ImageView might be the most interesting feature of Glide. And yes, you can't do that with Picasso. Some important links-
I think the better library to handle gif files is this one: by koral
Used it and i'm successful and this library is dedicated to GIF'S; but where as the picasso and glide are general purpose image framework; so i think the developers of this library have entirely concentrated on gif files