还放(main/Asset/htmls/name.gif)[此html可根据大小调整]
例如,在XML中声明如下(main/res/layout/name.xml):[例如,定义大小]
在您的活动中,将下一段代码放入onCreate中web = (WebView) findViewById(R.id.webView); web.setBackgroundColor(Color.TRANSPARENT); //for gif without backgroundweb.loadUrl("file:
///android_asset/htmls/name.html");
如果要动态加载,则必须使用数据加载Web视图:// or "[path]/name.gif" (e.g: file:///android_asset/name.gif for resources in asset folder), and in loadDataWithBaseURL(), you don't need to
set base URL, on the other hand, it's similar to loadData() method.String gifName = "name.gif";String yourData = "
\n" +
"
\n" +" \n" +
" \n" +
" ";// Important to add this attribute to webView to get resource from outside.webView.getSettings().setAllowFileAcces
s(true);// Notice: should use loadDataWithBaseURL. BaseUrl could be the base url such as the path to asset folder, or SDCard or
any other path, where your images or the other media resides related to your htmlwebView.loadDataWithBaseURL("file:///android_ass
et/", yourData, "text/html", "utf-8", null);// Or if you want to load image from SD card or where else, here is the idea.String
base = Environment.getExternalStorageDirectory().getAbsolutePath().toString();webView.loadDataWithBaseURL(base + '/', yourData, "t
ext/html", "utf-8", null);
就这样,我希望你能帮上忙。