Android WebView:如何让CSS使用绝对位置的整个高度?
我有一个响应迅速的html/css页面,该页面使用position:absolute将元素放置在适当的位置.例如用户名输入将具有
I have a very responsive html/css page that uses position:absolute to put elements in place. e.g. a username input will have
position:absolute;
top:30%;
height:8%;
left:35%;
right:65%;
所有内容在所有浏览器中均能正常运行,但webView android的高度存在问题.
Everything works well in all browsers but webView android has a problem with the height.
似乎它适应了内容的高度,而不是像其他浏览器那样处于"特定高度,并让css处理该任意高度.
It seems that it adapts itself to the height of the content instead of "being" of a certain height like any browser, and let the css deal with that arbitrary height.
我看不到宽度有任何问题,但这可能是一种错觉.
I don't see any issue with the width but that might be an illusion.
我尝试在视口元标记中使用和不使用height = device-height.不改变任何东西.
I tried with and without height=device-height in the viewport meta tag. Does not change anything.
这是我的webView代码:
Here's my webView code:
public void openWebview(String url){
WebView webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
webView.setWebViewClient(new ourViewClient());
try {
webView.loadUrl(url);
} catch (Exception e) {
e.printStackTrace();
}
}
public class ourViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
因此,在我的情况下,问题是我使用align parent而不是math_parent来设置WebView的高度.
So in my case the problem was that I was setting the height of WebView using align parent instead of math_parent.
我在用这个:
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
正确的方法,而不是正确的方法
instead of this, THE RIGHT WAY:
android:layout_width="match_parent"
android:layout_height="match_parent"