如何在Android手机上正确显示加载图像
我一直在尝试使用资源中的 .gif 文件,但加载时没有任何动静。我在执行异步任务时将其用作加载图像。我以前使用进度对话框,但现在我想自己显示图像而不使用对话框。如何才能正确显示该图像?
I have been trying to use a .gif file from my resources, but I get no movement when it loads. I am using it as a loading image while I am doing an asynchronous task. I was previously using a progress dialog but now I would like to display the image myself and not use a dialog. How can I get this image to display correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用AnimationDrawable:
http://developer.android.com/reference/android/graphics/drawable /AnimationDrawable.html
基本上,您应该将 gif 中的每个帧拆分为单独的文件 - 例如 .png 文件(假设它具有透明度),并在中指定这些文件; 代替。您还可以控制每帧的持续时间。
请参阅链接以获取代码示例
Try using AnimationDrawable:
http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html
Basically, you should split each of the frames in your gif into separate files - such as .png file (say if it had transparency) and specify these files in the
<animation-list>
instead. You can also control the duration of each frame.See the link for code example
如果您执意要使用 gif 图像,您可以使用 WebView 而不是 ImageView。然后制作一个显示 gif 图像的 html 文档。当您在 WebView 中显示它时,它将为您呈现动画。
If you are deadset on using a gif image you can just use a WebView instead of an ImageView. Then make an html doc that displays your gif image. When you show it in the WebView it will be animated for you.