Friday, April 11, 2014

Animated GIF ImageView Library for Android

Okay Good People!!!
Announcing today a brand new library which is intended to help you out with displaying Animated GIF's within your applications.

WHY A NEW LIBRARY?
As an Android developer you would have noticed that Android has not provided support for Animated GIF's as a component.
Therefore in order to show an Animated GIF's we usually end up using WebView in application which has its own disadvantages (Memorish Isuuess!!!).

THAY THE LIBRARY!
https://github.com/abhinavasr/giflib

Screenshot of Sample Application

The Sample application demonstrate that the Library Can handle both regular Image (PNG/JPG) and Animated GIF on same View. Therefore giving developer the flexibility to use Image/GIF without making any changes to his/her code base.


Sample Implementation:
layout.xml

        android:id="@+id/animatedGifImageView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_above="@+id/button1"
        android:layout_below="@+id/textView1" />


Activity.java
animatedGifImageView = ((AnimatedGifImageView)findViewById(R.id.animatedGifImageView));
animatedGifImageView.setAnimatedGif(R.raw.animated_gif,
TYPE.FIT_CENTER);
That's It!

AnimagedGifImageView supports some basic parameters to give you better control of image resizing (If required) There fore you can pass :

FIT_CENTER: Stretch and fit image while maintaining aspect ratio
STREACH_TO_FIT: Stretch Image irrespective of aspect ratio
AS_IS: Place the image without any manipulations.

Hope you will use the library and make your life easier :)


17 comments:

sourabh jain said...

It works fine. Thanks for your help. Can you please tell me How can I set height and width of GIFImageView..

sourabh jain said...

Please tell me how can I set height and width..

newbie said...

can you please add the complete code of your sample app? what is AnimatedGifImageView? as in android studio I'm receiving an error with this.

Unknown said...

Hey Saurabh, simply set the size of GifImageView like you will do for any View. And set the image inside as fit XY.

@Newbie: You can use the sample provided with the library itself. Cheers. https://code.google.com/p/giflib/source/browse/src/com/abhi/gif/lib/example/MainActivity.java

Anonymous said...

Thank you for the Library. It works but, the size of the gif image is not stable. I used a timer to show different animated images once in 10 seconds, and eachtime the size differs (I used different flags and it wont help : STREACH_TO_FIT, AS_IS, FIT_CENTER). I tried to invalidate, but it didnt solve the problem. Any idea why this happens?
Also it looks like there is a memory leak. I use the library to show a list of files, and the memory usage is increasing as time goes and is not returned by GC.

Unknown said...

This solution is not works in Android 4.0.4

Anonymous said...

first, thanks for tutorial, i follow this code and work fine..
i try to add something diferent, i load gif image from local storage,but i get this logcat java.io.IOException.. how i fix this? i want show gif image from local storage,thanks.

Mahesh Flutter said...

can u please provide link of library from where to download.

Unknown said...

https://giflib.googlecode.com/archive/a7d47d06a304874671d3fd62e8398510c7b1d428.zip

Anonymous said...

I use AnimatedGifImageView in listview. but error java.lang.NullPointeEexception

Naag said...

with your library i am able to show the GIF but the problem is the GIF is looping.
WHere as the same GIF if i open in browser it is not looping. I only created the GIF with no loop.

Anonymous said...

Its working fine. Could you please tell me how to set gif image path from Activity instead of giving hard coded from init method of GifView class.

Unknown said...

i did work for me, thank u buddy

Unknown said...

Awesome work. It works fine

shanaya said...

wow..its work
can you please tell me if i have 20 gif images...and i want images changes on button click thanks!

Unknown said...

Hi!

I would like to download Your library but there's nothing on GitHub.

Unknown said...

The link has been updated.