Android WebView 宽度
我正在尝试控制 WebView 的宽度比例。 经过整整两天的时间。我仍然停留在我开始的地方。 我已遵循以下文档: http://developer.android.com/guide/webapps/targeting.html http://developer.android.com/guide/practices/screens_support.html
我已经尝试过元标记、css、WebView.setInitialScale。 有时,这些更改会使 WebView 剪掉屏幕的中间部分,有时甚至剪掉三分之一。 当您认为自己在疯狂中找到了可预测的模式时,您会发现布局响应完全是随机的。 有谁知道是否有办法在 Android 平台上实现嵌入式 HTML5 网页,还是只是 Android 平台尚未准备好?
I'm trying to control the width scale of a WebView.
After spending about two full days. I'm still left where i started.
I have followed the following documentation:
http://developer.android.com/guide/webapps/targeting.html
http://developer.android.com/guide/practices/screens_support.html
I have experimented with the meta tags, css, WebView.setInitialScale.
Sometimes the changes makes the WebView clip the middle of the screen out, sometimes one third.
When you think you have found a predictable pattern in the madness, you find out that layout response is total random.
Does anybody know if there is a way forward implementing embedded HTML5 web pages on the Android platform or is it just something that the Android platform isn't ready for yet?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定你到底哪里出了问题,但这里有一些我用来测试嵌入式 WebView 的样板代码。我应该提到的是,我主要针对 Honeycomb (3.x),但您没有指定:
这是简单的示例布局:
现在这是 Activity 支持者的代码:
...这就是您需要嵌入 html5 页面的全部内容。您还可以将 html 页面放入“assets”文件夹中并使用以下方式加载它:
或者仅嵌入单个资源,例如
或使用之前相同的加载 URL 语法将其指向您的服务器
...我希望这会有所帮助...
I'm not sure where exactly you went wrong but here's some boilerplate code I use for testing my embedded WebViews. I should mention that I mainly target Honeycomb (3.x), but you didnt' specify so:
Here's the simple sample layout:
Now here's the code for the Activity backer:
...and that's all you need to have an embedded html5 page. You can also put your html page into your "assets" folder and load it using:
or embed just a single resource like
or just point it to your server using the same load URL syntax from before
... i hope this helps...
我得出的结论是,修改 WebView 宽度的唯一方法是操纵 html 元标记中找到的目标密度dpi
通过将目标密度 dpi 设置为我的设备宽度,我可以使网页跨越屏幕的整个宽度。
通过在运行时创建 html 文件,我可以用检测到的设备宽度填充目标密度dpi。哎呀!!
I have reached the conclusion that the only way to modify the WebView width is to manipulate the target-densitydpi found in the html meta tag
By setting the target-densitydpi to my device width i get the web page to span the entire width of the screen.
By creating the html file at runtime i can fill in the target-densitydpi with the detected device width. Yikes!!