Android的,WebView.getWidth()== window.innerWidth [英] Android, WebView.getWidth() == window.innerWidth
问题描述
我应该使用什么的在Java中的HTML META标签设置和WebSettings结合,得到以下结果:window.innerWidth在Javascript中应始终(任何Android版本和任何设备上),等于像素的WebView的宽度。
例如,我的WebView中设置宽度为1,024像素。在Android中AVD模拟器,window.innerWidth等于683px(1024 2/3,或150%比例)。
我尝试以下META:
< META NAME =视口CONTENT =WIDTH =设备的宽度;
用户可扩展性=无;初始规模= 1.0;
最小尺度= 1.0;最大规模= 1.0;/>
- 不工作
然后我尝试:
_WebView.getSettings()setLoadWithOverviewMode(真)。
。_WebView.getSettings()setUseWideViewPort(真);
_WebView.setInitialScale(100);
- 没有工作过。
最后,
_WebView.getSettings()setDefaultZoom(ZoomDensity.FAR)。
似乎是工作。根据文档,它的意思是100%在240dpi看上去像。我不知道,用户设备具有的dpi的!如何获得任务的正确完成?
更新
我刚刚测试过ZoomDensity.FAR在高DPI的平板电脑 - 它的作品的没有的它,不工作的与的它
问候,
-
META:
META NAME =视口CONTENT =WIDTH =设备的宽度;用户可扩展性=无;初始规模= 1.0;
最小尺度= 1.0;最大规模= 1.0; 目标densityDpi =设备DPI ; -
Java的:
_WebView.getSettings()setLoadWithOverviewMode(真);
。_WebView.getSettings()setUseWideViewPort(真);
这个组合的效果。
What combination of META tag settings in HTML and WebSettings in Java should I use to get the following result: window.innerWidth in Javascript should be always (in any Android version and on any device) equal to the WebView width in pixels.
For instance, I set the WebView width to 1024px. In Android AVD emulator, window.innerWidth is equal to 683px (2/3 of 1024, or 150% scale).
I tried the following META:
<meta name="viewport" content="width=device-width;
user-scalable=no; initial-scale=1.0;
minimum-scale=1.0; maximum-scale=1.0;" />
-- doesn't work.
Then I tried:
_WebView.getSettings().setLoadWithOverviewMode(true);
_WebView.getSettings().setUseWideViewPort(true);
_WebView.setInitialScale(100);
-- doesn't work too.
Finally,
_WebView.getSettings().setDefaultZoom(ZoomDensity.FAR);
seems to be working. According to documentation, it means "100% looking like in 240dpi". I don't know, what dpi users device has! How to get the task done correctly?
UPDATE
I've just tested ZoomDensity.FAR on a high-dpi tablet -- it works without it and doesn't work with it!
Regards,
META:
meta name="viewport" content="width=device-width; user-scalable=no; initial-scale=1.0; minimum-scale=1.0; maximum-scale=1.0; target-densityDpi=device-dpi;"
Java:
_WebView.getSettings().setLoadWithOverviewMode(true); _WebView.getSettings().setUseWideViewPort(true);
This combination works.
这篇关于Android的,WebView.getWidth()== window.innerWidth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!