Android WebView:如何让CSS使用绝对位置的整个高度? [英] Android WebView: how to let the css use the entire height w/ position absolute?

查看:131
本文介绍了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"

这篇关于Android WebView:如何让CSS使用绝对位置的整个高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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