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 found a very easy way, with a nice and simple working example here
display animated widget
Before getting it working there are some chages to do do in the code
IN THE FOLLOWING
just replace
in
AND IN
Provide your own gif animation file
REPLACE THE FIRST LINE IN
according to the name of the class...
after done this little changes it should work as for me...
hope this help
Similar to what @Leonti said, but with a little more depth:
What I did to solve the same problem was open up GIMP, hide all layers except for one, export it as its own image, and then hide that layer and unhide the next one, etc., until I had individual resource files for each one. Then I could use them as frames in the AnimationDrawable XML file.
@PointerNull gave good solution, but it is not perfect. It doesn't work on some devices with big files and show buggy Gif animation with delta frames on pre ICS version. I found solution without this bugs. It is library with native decoding to drawable: koral's android-gif-drawable.
I solved this by spliting gif in frames and use standard android animation
also put (main/assets/htmls/name.gif) [with this html adjust to the size]
declare in your Xml for example like this (main/res/layout/name.xml): [you define the size, for example]
in your Activity put the next code inside of onCreate
if you want load dynamically you have to load the webview with data:
suggestion: is better load gif with static images for more information check https://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html
That's it, I hope you help.
Use ImageViewEx, a library that makes using a gif as easy as using an
ImageView
.