[英]Android WebView viewport
With html below I expected that the green rectangle would occupy only half of the screen, but in practice it occupies the whole screen width. 使用下面的html我预计绿色矩形只占据屏幕的一半,但实际上它占据整个屏幕宽度。 I tried other values for viewport width, no luck. 我为视口宽度尝试了其他值,没有运气。 Any ideas why it does not work? 任何想法为什么它不起作用?
Html HTML
<html>
<head>
<meta name="viewport" content="width=640" />
</head>
<body>
<div style="width: 300px; height: 50px; background: green;">300px</div>
<div style="width: 600px; height: 50px; background: yellow;">600px</div>
</body>
</html>
Xml XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<WebView
android:id="@+id/web_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
I had the same question and found answer! 我有同样的问题,找到了答案!
In your case you need: 在您的情况下,您需要:
WebSettings settings = webView.getSettings();
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);
Partially solved, now I can scale by double tap: 部分解决,现在我可以通过双击扩展:
webView.getSettings().setUseWideViewPort(true);
EDIT: No, I was wrong... I changed the test html, and found that it scales to page width - 1000px, and not to the viewport width - 640px. 编辑:不,我错了...我改变了测试html,发现它扩展到页面宽度 - 1000px,而不是视口宽度 - 640px。
<div style="width: 300px; height: 50px; background: green;">300px</div>
<div style="width: 600px; height: 50px; background: yellow;">600px</div>
<div style="width: 1000px; height: 50px; background: red;">1000px</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.