Android中WebView底部的空白

发布于 2024-12-11 13:29:17 字数 1471 浏览 1 评论 0原文

我正在开发一个 Android 应用程序,并且正在 WebView 中加载一个谷歌地图 iframe,就像这样:

http://maps.google.es/maps/empw?url=http:%2F%2Fmaps.google.es%2Fmaps%3Ff%3Dq%26源%3Ds_q%26hl%3Des%26geocode%3D%26q%3Dmadrid%26aq%3D%26sll%3D40.396764,-3.713379%26sspn %3D11.856886,23.269043%26vpsrc%3D0%26ie%3DUTF8%26hq%3D%26hnear%3DMadrid,%2BComunidad%2Bde%2 BMadrid%26t%3Dm%26z%3D10%26ll%3D40.416691,-3.700345%26output%3Dembed&hl=es&gl=es

它在 Android 模拟器中显示正确,但是当我在真实设备中尝试时,屏幕底部会出现相当大的空白,因此您看不到整个 iframe。我尝试了两部手机,一部是 android 2.2,另一部是 android 2.3

我看了一下这个,听起来是一样的:

android Webview 底部有额外空间的问题

但它对我不起作用。还尝试了我读到的其他一些事情,例如:

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:

http://maps.google.es/maps/empw?url=http:%2F%2Fmaps.google.es%2Fmaps%3Ff%3Dq%26source%3Ds_q%26hl%3Des%26geocode%3D%26q%3Dmadrid%26aq%3D%26sll%3D40.396764,-3.713379%26sspn%3D11.856886,23.269043%26vpsrc%3D0%26ie%3DUTF8%26hq%3D%26hnear%3DMadrid,%2BComunidad%2Bde%2BMadrid%26t%3Dm%26z%3D10%26ll%3D40.416691,-3.700345%26output%3Dembed&hl=es&gl=es

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

落叶缤纷 2024-12-18 13:29:17

我可以看到<身体>您发布的链接中的元素的下边距为 14px - 也许就是这样?加载页面后,您可以在 WebView 中使用 JavaScript 代码片段来消除它,如下所示:

myWebView.loadUrl("javascript:document.getElementsByTagName('body')[0].style.marginBottom = '0px'");

另外,右侧有一个 44px 的边距,如果您也想删除该边距,应该是这样的:

myWebView.loadUrl("javascript:document.getElementsByTagName('body')[0].style.marginBottom = '0px';document.getElementsByTagName('body')[0].style.marginRight = '0px';");

另外,为了让您的应用程序面向未来,您可能需要将所有四个边距设置为 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:

myWebView.loadUrl("javascript:document.getElementsByTagName('body')[0].style.marginBottom = '0px'");

also, there is a 44px margin on the right, if you wanna get rid of that one also, should be something like this:

myWebView.loadUrl("javascript:document.getElementsByTagName('body')[0].style.marginBottom = '0px';document.getElementsByTagName('body')[0].style.marginRight = '0px';");

Also, to future-proof your app, you may want to set all four margins to 0, just in case.

私藏温柔 2024-12-18 13:29:17

将下边距和右边距设置为 0:

webView.loadUrl("javascript:document.body.style.marginBottom=document.body.style.marginBottom= '0px'");

Set the bottom and right margins to 0:

webView.loadUrl("javascript:document.body.style.marginBottom=document.body.style.marginBottom= '0px'");
锦爱 2024-12-18 13:29:17

这可能是您的 XML 的问题。

您能否检查您的 WebView 是否不在 ScrollView 或任何具有内置滚动的内容内。它可能会导致额外的空白。

It could be the problem with your XML.

Can you check that your WebView is not inside the ScrollView or anything which is having its inbuilt scroll. It might result in extra white spaces.

貪欢 2024-12-18 13:29:17

其他答案对我不起作用,但这确实有效:

webView.loadUrl("javascript:(function () {document.getElementsByTagName('body')[0].style.marginBottom = '0'})()");

The other answers didn't work for me but this did:

webView.loadUrl("javascript:(function () {document.getElementsByTagName('body')[0].style.marginBottom = '0'})()");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文