Search code examples
androidgifandroid-9.0-pieanimatedimagedrawable

How to use AnimatedImageDrawable (GIF image) before API 28?


In API 28 AnimatedImageDrawable was introduced for displaying gif images:

https://developer.android.com/reference/android/graphics/drawable/AnimatedImageDrawable.html

Drawable for drawing animated images (like GIF).

The problem is that they don't told anything about how to use it with AppCompat-v7 or Support-v4 libraries for retrocompatibility before API 28.

Does anyone know if is possible to use it before API 28 for displaying GIF images?


Solution

  • Short answer: No, you can't use AnimatedImageDrawable below API 28 and there is no compat version of the class.

    For your problem you have different options based on your situation:

    1. If in your app you are already using Picasso or Glide, they both handle GIF images automatically and you can use them in place of AnimatedImageDrawable (I discourage you to add those big libraries just to handle GIF if you don't need the other features they provide).
    2. You can use a WebView embedding the image in an HTML and then loading the HTML page inside the WebView
    3. Use a known library to do that which is API 17+, called Android Gif Drawable

    For both options 1 and 2 you can find plenty of examples online. Some of them are in this thread: