在 API 28 中引入了用于显示 gif 图像的 AnimatedImageDrawable
:
https://developer.android.com/reference/android/graphics/drawable/AnimatedImageDrawable.html
Drawable for drawing animated images (like GIF).
问题是他们没有说明如何将它与 AppCompat-v7
或 Support-v4
库一起使用以实现 API 28 之前的追溯兼容性。
有谁知道是否可以在 API 28 之前使用它来显示 GIF 图像?
最佳答案
简短回答:不,您不能在 API 28 以下使用 AnimatedImageDrawable
,并且该类没有兼容版本。
对于您的问题,您根据自己的情况有不同的选择:
- 如果您已经在您的应用中使用了
Picasso
或Glide
,它们都会自动处理 GIF 图像,您可以使用它们代替 AnimatedImageDrawable(我不鼓励您添加如果您不需要它们提供的其他功能,那些大型库只是为了处理 GIF)。 - 您可以使用
WebView
将图像嵌入到 HTML 中,然后将 HTML 页面加载到 WebView 中 - 使用已知库执行 API 17+,称为 Android Gif Drawable
For both options 1 and 2 you can find plenty of examples online. Some of them are in this thread:
关于android - API 28之前如何使用AnimatedImageDrawable(GIF图片)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58138467/