我知道很多人已经问过如何在 Android 中显示 GIF 图片,但大多数答案都有最多的问题:
- 他们使用现已弃用的库。
- 他们使用不允许暂停(和恢复)动画的库,这是我愿意做的事情。
目前最简单的方法是什么?
最佳答案
有一个很好的库可以在您的应用中显示 GIF 图像。 android-gif-drawable
它在 XML 和 Java 中都有很好的用法。它还为您提供了一个非常易于使用的 API。
以下是您可能感兴趣的方法列表:
GifDrawable
implements anAnimatable
andMediaPlayerControl
so you can use its methods and more:
stop()
- stops the animation, can be called from any threadstart()
- starts the animation, can be called from any threadisRunning()
- returns whether animation is currently running or notreset()
- rewinds the animation, does not restart stopped onesetSpeed(float factor)
- sets new animation speed factor, eg. passing 2.0f will double the animation speedseekTo(int position)
- seeks animation (within current loop) to given position (in milliseconds)getDuration()
- returns duration of one loop of the animationgetCurrentPosition()
- returns elapsed time from the beginning of a current loop of animation
关于Android:显示和暂停 GIF 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33638561/