Android:显示和暂停 GIF 图像

标签 android animated-gif

我知道很多人已经问过如何在 Android 中显示 GIF 图片,但大多数答案都有最多的问题:

  • 他们使用现已弃用的库。
  • 他们使用不允许暂停(和恢复)动画的库,这是我愿意做的事情。

目前最简单的方法是什么?

最佳答案

有一个很好的库可以在您的应用中显示 GIF 图像。 android-gif-drawable

它在 XML 和 Java 中都有很好的用法。它还为您提供了一个非常易于使用的 API。

以下是您可能感兴趣的方法列表:

GifDrawable implements an Animatable and MediaPlayerControl so you can use its methods and more:

  • stop() - stops the animation, can be called from any thread
  • start() - starts the animation, can be called from any thread
  • isRunning() - returns whether animation is currently running or not
  • reset() - rewinds the animation, does not restart stopped one
  • setSpeed(float factor) - sets new animation speed factor, eg. passing 2.0f will double the animation speed
  • seekTo(int position) - seeks animation (within current loop) to given position (in milliseconds)
  • getDuration() - returns duration of one loop of the animation
  • getCurrentPosition() - returns elapsed time from the beginning of a current loop of animation

关于Android:显示和暂停 GIF 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33638561/

相关文章:

android - 在 GridView 的顶部和底部添加空间

php - 如何将json数组数据插入mysql?

Android ListView setSelection() 似乎不起作用

java - 如何解决java.lang.RuntimeException : Unable to start activity ComponentInfo

objective-c - 在 iOS10 上生成的 GIF 图像不再在浏览器上永远循环

android - 将进度微调器插入启动画面 android

gif - 如何从一堆 jpg 中创建 gif 动画

Javascript:动画 GIF 到数据 URI

c# - 使用 BitmapEncoder 生成时如何使 GIF 循环重复

java - 将动画 gif 从 JAR 文件加载到 ImageIcon