是否可以在 Android 中播放 GIF 格式?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3163706/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 08:59:00  来源:igfitidea点击:

Is it possible to play GIF format in Android?

androidanimated-gif

提问by antony

I want to add play gif format to my android app. Could this be done, and how would I do it?

我想将播放 gif 格式添加到我的 android 应用程序中。这能做到吗,我该怎么做?

回答by Janusz

It seems that playing animated GIFs is not supported directly in Android. The Google docsstate the GIF is a discouraged file type for using in your Android projects.

似乎在 Android 中不直接支持播放动画 GIF。在谷歌文档注明GIF是使用你的Android项目气馁文件类型。

There are some possibilities but they all seem to require a great deal of work to show your animated GIFs.
The one thing that seems to be working is splitting up the GIF into its frame and do the animation between the frames yourself, see this questionfor a little bit more information. There is also this questionthat shows another way but the answer may be outdated because of the changes made in the cupcake release that are mentioned in the other questsion.

有一些可能性,但它们似乎都需要大量工作才能显示您的动画 GIF。
似乎正在起作用的一件事是将 GIF 分成其帧并自己在帧之间制作动画,请参阅此问题以获取更多信息。还有这个问题显示了另一种方式,但由于其他问题中提到的纸杯蛋糕版本中的更改,答案可能已经过时。

回答by Hardik Nadiyapara

You should see the API demo example for using .gif file in Your application i put the link http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/BitmapDecode.html

你应该看到在你的应用程序中使用 .gif 文件的 API 演示示例我把链接放在 http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/BitmapDecode.html

回答by Artur Zielazny

Animated GIFs are supported since Android Froyo (2.2).

自 Android Froyo (2.2) 起支持动画 GIF。

Earlier versions does not support animated GIFS out of the box. You can take a look at the Android Issue 3422for more details.

早期版本不支持开箱即用的动画 GIFS。您可以查看Android 问题 3422以了解更多详细信息。

回答by senola

You can extract the frames from the GIF and then use a frame-by-frame animation to animate these frames in android.

您可以从 GIF 中提取帧,然后使用逐帧动画在 android 中为这些帧设置动画。

For more information on the frame-by-frame animation you can take a look at the tutorial provided at http://www.app-solut.com/blog/2011/05/playing-animations-in-android/

有关逐帧动画的更多信息,您可以查看http://www.app-solut.com/blog/2011/05/playing-animations-in-android/ 上提供的教程