Android 的 WebView 可以自动调整大图像的大小吗? [英] Can Android's WebView automatically resize huge images?

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

问题描述

在某些网络浏览器中,大图像会自动调整大小以适合屏幕.

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.

推荐答案

是的,这是可能的.您可以尝试使用以下代码设置 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天全站免登陆