Display Animated GIF

后端 未结 30 2099
无人及你
无人及你 2020-11-22 02:11

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

30条回答
  •  攒了一身酷
    2020-11-22 02:52

    Ways to show animated GIF on Android:

    • Movie class. As mentioned above, it's fairly buggy.
    • WebView. It's very simple to use and usually works. But sometimes it starts to misbehave, and it's always on some obscure devices you don't have. Plus, you can’t use multiple instances in any kind of list views, because it does things to your memory. Still, you might consider it as a primary approach.
    • Custom code to decode gifs into bitmaps and show them as Drawable or ImageView. I'll mention two libraries:

    https://github.com/koral--/android-gif-drawable - decoder is implemented in C, so it's very efficient.

    https://code.google.com/p/giffiledecoder - decoder is implemented in Java, so it's easier to work with. Still reasonably efficient, even with large files.

    You'll also find many libraries based on GifDecoder class. That's also a Java-based decoder, but it works by loading the entire file into memory, so it's only applicable to small files.

提交回复
热议问题