机器人的WebView,缩放图片以适应屏幕 [英] Android WebView, Scaling Image to fit the screen
问题描述
我有什么:我是从一个URL加载图像。我简单地做(web视图).loadUrl(IMAGEURL,extraheaders)
What I have: I'm loading image from a URL. I simply do (WebView).loadUrl(imageurl, extraheaders)
我所得到的:图片没有显示在web视图的整个宽度,它有空白各地(比如,如果你在你的桌面浏览器中打开一个小iamge)
What I get: Image is not showing at full width of the WebView, it has blank space all around (like if you open a little iamge in your desktop browser)
我的尝试:设置LayoutAlgorithm到SINGLE_COLUMN。作品完美,但变焦不工作。 (我有它在 WebView.getSettings()
不知道为什么设置 setUseWideViewPort(真)启用。
加载图像无任何空白空间,但它完全放大
What i tried: Setting LayoutAlgorithm to SINGLE_COLUMN. Works perfect, but zooming doesn't work. (I have it enabled in the WebView.getSettings()
Dont know why. Setting setUseWideViewPort(true);
load image without any blanks space, but it is fully zoomed in.
推荐答案
我有同样的问题,这样做只是正常工作:
I had the same issue and doing this worked just fine:
Display display = getWindowManager().getDefaultDisplay();
int width=display.getWidth();
String data="<html><head><title>Example</title><meta name=\"viewport\"\"content=\"width="+width+", initial-scale=0.65 \" /></head>";
data=data+"<body><center><img width=\""+width+"\" src=\""+url+"\" /></center></body></html>";
webView.loadData(data, "text/html", null);
这篇关于机器人的WebView,缩放图片以适应屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!