您的位置:首页 > 移动开发

webView图片自适应屏幕

2017-05-10 15:45 447 查看

解决webView图片过大 不能自适应屏幕

后台返回的图片太大,还需要左右滑动,或者图片太小不能铺满整个屏幕


1.添加依赖

compile  'org.jsoup:jsoup:1.10.1'


2.写一个工具类,专门解析图片标签 img

public class HtmlFormat {

public static 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();
}
}


3.可以直接使用了

webView = (WebView) view.findViewById(R.id.wb_view);

webView.loadDataWithBaseURL(null, HtmlFormat.getNewContent(data.content), "text/html", "UTF-8", null);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: