An implementation of an Android Drawable, using the decoder, as a simple way to display a gif in an Android app.
android-drawable
is available on mavenCentral()
Add it to your dependencies with implementation "app.redwarp.gif:android-drawable:x.y.z"
In code, create a GifDrawable from any InputStream.
GifDrawable implements Animatable2Compat
, a user needs to call start()
to start the animation.
// Example: with a gif included in your app as an asset
val inputStream = context.assets.open("some_animated.gif")
val drawable:GifDrawable = GifDrawable.from(inputStream)
drawable.start()
imageView.setImageDrawable(drawable)
This library depends on:
- AppCompat, as the
GifDrawable
implements Animatable2Compat.
If you target Android 28, AnimatedImageDrawable is good and efficient. Below 28, it's not crystal clear what should be used.
Coil and Glide both bake their own version of a Gif decoder.
- The Coil version relies on the
Movie
class and is quite expensive in term of memory and CPU usage. See MovieDrawable. - The Glide version is decent, see StandardGifDecoder.