的WebView不调整 [英] WebView doesn't resize

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

问题描述

我已经开发了Web应用程序为Firefox OS,但我想让它在Android上运行本地。我的应用程序包含一个对话框,这是一个 DIV 填补我使用Firefox响应式设计工具,测试过整个页面时看到,和它正确调整大小。当软键盘出现,我希望这一对话,以调整到遗留下来的视口有一些按钮,在对话框的底部。

I've developed a web application for Firefox OS, but I wanted to make it run "natively" in Android. My application consists of a dialogue box that is a div which fills the entire page when visible, which I've tested using the Firefox responsive design tool and it does resize correctly. When a soft keyboard appears, I would want the dialogue to resize to the viewport left over as there are some buttons at the bottom of the dialogue.

我创建了一个活动的应用程序,只包含一个的WebView 。我想的视图显示在键盘的时候来调整,所以我用:

I created an application with a single activity that contains just a WebView. I wanted to the view to resize when the keyboard appears, so I used:

android:windowSoftInputMode="stateUnspecified|adjustResize"

这似乎没有任何区别的的WebView 时,键盘是可见的。我上网看了一下,其中有不少人抱怨这个问题,但他们都有共同的同样的事情,他们使用了 Theme.Black.NoTitleBar.Fullscreen 主题,我不是。我尝试了所有的办法,解决问题,但他们都不工作。

which didn't seem to make any difference to the WebView when the keyboard was visible. I looked online and there were many people complaining about this problem, but they all had the same thing in common, they were using the Theme.Black.NoTitleBar.Fullscreen theme, which I am not. I tried all of the solutions to that problem, but none of them worked.

然后我就开始,如果有在的WebView 这意味着它没有调整的错误产生了怀疑。所以,我写了一个自定义的查看其打印的尺寸 onLayout

I then began to wonder if there was a bug in WebView which meant it didn't resize. So, I wrote a custom View which printed the dimensions in onLayout.

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    Log.d(TAG, t + " " + r + " " + b + " " + l);
}

果然,有人被调整正确时,键盘出现并disappared。所以,我做了一些调查研究,我发现了一些答案,说你需要隐藏的WebView ,重新加载它,然后再次显示它。

And sure enough, the view was being resized correctly when the keyboard appeared and disappared. So, I did some more research and I found a few answers that said that you need to hide the WebView, reload it, and then show it again.

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    Log.d(TAG, t + " " + r + " " + b + " " + l);

    mWebView.setVisibility(View.GONE);
    mWebView.layout(l, t, r, b);
    mWebView.invalidate();
    mWebView.reload();
    mWebView.setVisibility(View.VISIBLE);
}

此外,这并没有解决我的问题。 (作为一个次要的一点,这是一个网络应用程序,用一个.html文件和JS会导致应用程序中的所有元素的状态在运行时改变,所以重装它不是一个选项。)

Again, this did not solve my problem. (And as a side point, this is a web-app with a single .html file and JS causes the state of all the elements in the app to change in runtime, so reloading it is not an option.)

我的问题是,是否有人知道的大小调整的方式的WebView 一旦内容被加载时,键盘是可见的。

My question is whether anyone knows of a way of resizing a WebView once the content has been loaded when the keyboard is visible.

推荐答案

原来,这个问题是,我用的位置是:绝对位置是:固定 DIV 。外 DIV 已调整大小正常,但内层没有。究其原因,我不得不使用的位置是:绝对是因为,这意味着在WebKit中的一个错误,你不能转换 固定定位的div。

The problem turned out to be that I was using position: absolute inside a position: fixed div. The outer div was resizing properly, but the inner one was not. The reason I had to use position: absolute was because there is a bug in WebKit which means that you cannot transform fixed positioned divs.

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

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