android - 如何在 Android 中播放 GIF 文件?

标签 android gif android-image

我想在当前 Activity 中播放 GIF 文件。

我有一个 XML 文件,其中有一个布局。

我想在同一个类 Activity 中播放 GIF。

有没有一种简单的方法可以在 Activity 类中播放 GIF 文件?

最佳答案

您可以使用 WebView 。 我将举例说明:

//My activity
public class Gift_Loading extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Gif_loading_View view = new Gif_loading_View(this); 
        setContentView(view);
    }

}

//the webView
public class Gif_loading_View extends WebView{

    public Gif_loading_View(Context context) {

        super(context);     
        loadUrl("file:///android_asset/loading_position.html");

        } 
}

在 Assets 文件夹中添加这个 html 文件:

<html>
<body bgcolor="white">
    <table width="100%" height="100%">
        <tr>
            <td align="center" valign="center">                
                <br/>
                <br/>
                <br/>
                <font size="6">Please wait...</font>
                <br/>
                <br/>
                <img src="cyclist_loading.gif" />

            </td>
        </tr>
    </table>
</body>

关于android - 如何在 Android 中播放 GIF 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7306846/

相关文章:

android - Ionic 5 将 Android minSdkVersion 从 21 更改为版本 23

android - 如何检查线性布局中是否有可用空间

android - 如何将图像添加到android中的AlertDialog?

java - 使用 C/C++ 进行 Android 开发是否比 Java 更快?

android - 无法在 Android 中使用 WebView 加载网页

image - 为什么 GIF 格式不是最紧凑的自然图像格式?

internet-explorer - IE 停止时的 GIF 动画

c# - WinRT 将 Jpg 或 PNG 转换为 GIF

android - 将 Imageview 设置为在 sdcard 中显示图像?

android - 在 fragment 中自定义图像