Android中WebView底部的空白
我正在开发一个 Android 应用程序,并且正在 WebView 中加载一个谷歌地图 iframe,就像这样:
它在 Android 模拟器中显示正确,但是当我在真实设备中尝试时,屏幕底部会出现相当大的空白,因此您看不到整个 iframe。我尝试了两部手机,一部是 android 2.2,另一部是 android 2.3
我看了一下这个,听起来是一样的:
但它对我不起作用。还尝试了我读到的其他一些事情,例如:
webView.getSettings().setUseWideViewPort(true);
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading (WebView view, String url) {
view.loadUrl(url);
return false;
}
});
但没有任何效果。有什么想法吗?
提前致谢。
I'm developing an Android application and I'm loading one google maps iframe in a WebView, just like this one:
It is showing correctly in Android emulator, but when I try in a real device a white space quite big appears at the bottom of the screen, so you can't see the whole iframe. I tried with two mobiles, one with android 2.2 and another one with android 2.3
I had a look to this one which sounds the same thing:
Problem with extra space at the bottom of android Webview
but it didn't work for me. Also tried some other things I read about like:
webView.getSettings().setUseWideViewPort(true);
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading (WebView view, String url) {
view.loadUrl(url);
return false;
}
});
but nothing worked. Any idea?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我可以看到<身体>您发布的链接中的元素的下边距为 14px - 也许就是这样?加载页面后,您可以在 WebView 中使用 JavaScript 代码片段来消除它,如下所示:
另外,右侧有一个 44px 的边距,如果您也想删除该边距,应该是这样的:
另外,为了让您的应用程序面向未来,您可能需要将所有四个边距设置为 0,以防万一。
I can see the <body> element at the link you posted has bottom margin of 14px - maybe that's it? You can eliminate it using a JavaScript snippet in your WebView after you have loaded the page, like this:
also, there is a 44px margin on the right, if you wanna get rid of that one also, should be something like this:
Also, to future-proof your app, you may want to set all four margins to 0, just in case.
将下边距和右边距设置为 0:
Set the bottom and right margins to 0:
这可能是您的
XML
的问题。您能否检查您的
WebView
是否不在ScrollView
或任何具有内置滚动的内容内。它可能会导致额外的空白。It could be the problem with your
XML
.Can you check that your
WebView
is not inside theScrollView
or anything which is having its inbuilt scroll. It might result in extra white spaces.其他答案对我不起作用,但这确实有效:
The other answers didn't work for me but this did: