可Android的WebView功能自动调整图像巨大? [英] Can Android's WebView automatically resize huge images?

查看:147
本文介绍了可Android的WebView功能自动调整图像巨大?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某些Web浏览器,巨大的图片会自动调整大小以适应屏幕。

In some web browsers, huge images are automatically resized to fit the screen.

是否有可能在Android的WebView做?

Is it possible to do the same in an Android WebView?

该网页只包含图像,也许加入一些JavaScript可以做的伎俩?
任何人都已经做到了这一点?

The web page just contains the image, maybe adding some JavaScript could do the trick?
Anybody has already done this?

注:我不知道图像的大小提前

Note: I don't know the size of the image in advance.

推荐答案

是的,这是可能的。您可以尝试使用下面的code设置的WebView布局。它会调整所有图像至屏幕宽度(比设备屏幕宽度大)。这适用于两个方向(纵向和横向)

Yes, it's possible. You can try setting the WebView Layout using the code below. It resizes all Images (Greater than the Device Screen Width) to the Screen Width. This works for both Orientations (Portrait and Landscape)

webview.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);

您可以稍后再添加额外的利润/填充得到间距正确。

You can add extra margins/padding later to get the spacing right.

这篇关于可Android的WebView功能自动调整图像巨大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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