Android中WebView底部的空白 [英] White space at the bottom of WebView in Android

查看:508
本文介绍了Android中WebView底部的空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Android应用程序,并在WebView中加载一个Google Maps iframe,就像这样:

I'm developing an Android application and I'm loading one google maps iframe in a WebView, just like this one:

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

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:

在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?

谢谢.

推荐答案

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

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'");

此外,右侧还有一个44px的边距,如果您也想摆脱该空白,应该是这样的:

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';");

此外,为了使您的应用程序过时,您可能需要将所有四个边距都设置为0,以防万一.

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

这篇关于Android中WebView底部的空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆