【问题标题】:loading a view to webview.. [duplicate]将视图加载到 webview .. [重复]
【发布时间】:2014-08-07 08:20:34
【问题描述】:

我正在尝试从 assets 文件夹中加载 gif 图像。我正在关注以下链接

http://droid-blog.net/2011/10/14/tutorial-how-to-use-animated-gifs-in-android-part-3/

现在这里的问题是我的 gif 很大,所以只有一部分图像显示在视图中.. 因此我想

i want to display the gif in an xml file that has a webview as a child..

为了达到上述目的,我做了以下

 setContentView(R.layout.activity_splash_about);
 WebView webView = (WebView) findViewById(R.id.webView1);
 GifWebView view = new GifWebView(this, "file:///android_asset/ab.gif");     
 webView.addView(view); 

但出现以下错误

 Unable to open asset URL: file:///android_asset/ab.gif
 I/chromium(1139): [INFO:CONSOLE(12)] "Not allowed to load local resource:
                 file:///android_asset/webkit/android-weberror.png", 
                  source: data:text/html,chromewebdata (12)

那么如何在 xml 中的 webview 中显示视图??

【问题讨论】:

    标签: android view webview gif


    【解决方案1】:

    Web 视图支持 Gif,因此您需要生成自己的 html 文件,如下所示,

     <html>
    <body bgcolor="white">
        <table width="100%" height="100%">
            <tr>
                <td align="center" valign="center">
                    <font color="gray">Some text you display</font>
                    <br/>
                    <br/>
                    <br/>
                    <br/>
                    <br/>
                    <img src="yourGIF.gif">
                </td>
            </tr>
        </table>
    </body>
    

    将此 html 保存在您的评估文件夹中。在 web 视图中加载该 url

    webview.loadUrl("file:///android_asset/your_html.html");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-18
      • 2011-02-28
      • 2015-09-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多