调整WebView大小时如何使网页适合WebView的宽度(不重新加载) [英] How to fit web page to webview's width when webview resizes (without reloading)

查看:226
本文介绍了调整WebView大小时如何使网页适合WebView的宽度(不重新加载)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HTML页面和一个全屏的Android Webview. HTML内容大于Webview的可见区域.我想要使HTML内容适合Webview的宽度.

I have an HTML page and a full-screen Android webview. The HTML content is larger than the webview's visible area. I want to fit the HTML content to the width of webview.

真正重要的是:当设备方向发生变化时,Web视图将不会重新加载,这意味着它仅会调整大小,内容仍会 适应宽度.

What's really important is this: when the device's orientation changes, the webview will not reload, meaning it will just resize and the content would still fit to width.

另一件事:由于内容已按比例缩小,因此用户可以将其放大到最大比例100%.当内容缩放并且方向改变时,我希望将内容再次调整为适合宽度.

One more thing: because the content has been scaled down, user can zoom it in to a maximum scale of 100%. When the content is zoomed and orientation changes, I want the content to fit-width again.

编辑1 :我可以更改HTML开头的meta标签,但其内容仍然大于webview的可见区域.我支持Android 2.3及更高版本.

Edit 1: I can change meta tags in the head of HTML, but its content remains larger than the webview's visible area. I'm supporting Android 2.3 and later.

编辑2 :感谢您对响应式网页设计的建议.我知道这是什么,我可以做到.问题是在这种情况下,我无法更改很多HTML内容.

Edit 2: Thanks for the suggestion on responsive web design. I know what it is and I can do it. Problem is I cannot change much of the HTML content in this case.

TL; DR :如何在Webview调整大小时始终将较大的HTML内容调整为Android Webview的宽度,而不重新加载内容. (我可以更改Web视图,而无需更改HTML.)

TL;DR: How to always fit a larger HTML content to a Android webview's width as the webview resizes, without reloading the content. (I can change the webview, not much of the HTML.)

推荐答案

执行以下设置

    webview.getSettings().setUseWideViewPort(true);
    webview.getSettings().setLoadWithOverviewMode(true);

这篇关于调整WebView大小时如何使网页适合WebView的宽度(不重新加载)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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