把一个图像的WebView内,适应它的宽度 [英] Put an image inside a webview and fit it width

查看:102
本文介绍了把一个图像的WebView内,适应它的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一个web视图来显示图像可能大(为了抓住它的内存管理)。 为了测试我在web视图加载此code

I'd like to use a WebView for displaying images potentially big (in order to seize it memory management). For the test i'm loading this code in the WebView

<head></head>
<body>
    <img alt="test" src="file:///android_asset/cute-cat-sleeping.jpg">
</body>

现在的问题是,如果我加载它在网页原样。 web视图只允许进行缩小直到图像的第一尺寸为配合在屏幕上。在这个例子中,图像高度是完全示出到web视图然后不再变焦允许的:

The problem is that if I load it in a web "as is". The WebView only allow to zoom out until the first dimension of the image is fit in screen. In this example the image height is totally shown into the WebView and then no more zoom allowed:

正如你可以看到这种模式下不允许的全球形象的一个正确的显示,尽管当图像被放大在右侧和底部角落的行为是正确的,因为你可以在这里看到

As you can see this mode doesn't allow a correct display of the global image despite that when the image is zoomed the behaviour in the right and bottom corners are correct as you can see here

所以,我想在(web视图).getSettings()。setUseWideViewPort(真),结果是,我可以缩小大于图像的宽度

So I tried the (WebView).getSettings().setUseWideViewPort(true) and the result is that I can zoom out more than the image's width

和缩放的行为是不正确的,在右下边框:

and the zoomed behaviour is not correct in the bottom-right borders:

总结:我想最大缩小可能是ImageWidth等=的WebView的宽度和缩放行为就像在第二图像:

Summarizing: I'd like the max zoom out possible to be imageWidth=webview width and zoom behaviour like in the second image:

完整和/或有用的答案将bountied

Complete and/or usefull answers will be bountied

编辑:赏金打开Vinayak.B

Bounty opened for Vinayak.B

推荐答案

使用视窗元数据可以帮助你做到这一点。

Using Viewport Metadata may help you to do this

视口是在你的网页被绘制的区域。虽然视区的可见区域的屏幕的大小相匹配,则视口有其自己的尺寸决定的像素提供给一个网页

The viewport is the area in which your web page is drawn. Although the viewport's visible area matches the size of the screen, the viewport has its own dimensions that determine the number of pixels available to a web page

也可以尝试以下

WebSettings settings = webView.getSettings();
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);

这篇关于把一个图像的WebView内,适应它的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆