1.添加如下代码:
//添加html标签使图片自适应屏幕
String html = "<html><body width=320px style=\"word-wrap:break-word; font-family:Arial\">" + webviewhtml + "</body></html>";
2.用如下方式加载webview:
//webview加载html标签
mWebView.loadDataWithBaseURL(null, getNewContent(html) + "", "text/html", "utf-8", null);
3.getNewContnet方法
/**
* webview加载图片太大,自适应屏幕
* @param htmltext
* @return
*/
public String getNewContent(String htmltext){
Document doc= Jsoup.parse(htmltext);
Elements elements=doc.getElementsByTag("img");
for (Element element : elements) {
element.attr("width","100%").attr("height","auto");
}
return doc.toString();
}