android webView显示html图片比例缩放的效果

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010023795/article/details/53509495

webView显示html网页图片成比例缩放效果

在webView显示heml的时候,往往会有图片,但是后台或者前端往往不把html封装好,造成图片不是过大就是过小,还需要移动端封装一下。
这里为了能够让图片适应我们的屏幕成比例放大缩小成适合的尺寸我们自己封装一下,

//封装头文件
String sHead=   "<html><head><meta name=\"viewport\" content=\"width=device-width, " +
                    "initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes\" />"+
                    "<style>img{max-width:100% !important;height:auto !important;}</style>"
                    +"<style>body{max-width:100% !important;}</style>"+"</head><body>";

然后把设置好的头添加进去

webView.loadDataWithBaseURL(null,sHead+nd.getContent()+"</body></html>","text/html", "UTF-8", null);

这样设置就好了,其实前端的东西懂一点还是很必要的。

猜你喜欢

转载自blog.csdn.net/u010023795/article/details/53509495
今日推荐