在Android webview中,我加载了一个简单的html页面,其中的div设置为100%的宽度和高度。我在浏览器中工作得很好,但是在Galaxy Nexus 4.4.2上我看不到内容div。调试div时,它的内容似乎没有宽度。
以下是webview设置:
setScrollContainer(false);
setBackgroundColor(Color.RED);
setHorizontalScrollBarEnabled(false);
setHorizontalScrollbarOverlay(false);
setVerticalScrollBarEnabled(false);
setVerticalScrollbarOverlay(false);
this.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
WebSettings ws = getSettings();
ws.setSupportZoom(false);
ws.setJavaScriptEnabled(true);
ws.setUseWideViewPort(true);
ws.setLoadWithOverviewMode(true);
ws.setCacheMode(WebSettings.LOAD_NO_CACHE);
ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
ws.setAllowFileAccess(true);
ws.setAllowFileAccessFromFileURLs(true);下面是示例html:
<html>
<head>
<title>Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="cache-control" content="no-cache" />
<meta name="apple-mobile-web-app-capable" content="yes">
<meta id="myvp" name="viewport" content="width=400, height=300, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="./main.css">
</head>
<body>
<div class="component">
<input type="text">
</div>
</body>
</html>下面是css:
body {
background-color: blue;
}
.component {
width: 100%;
height: 100%;
background-color: green;
overflow: hidden;
}这样,我希望看到一个带有文本字段的绿色框。相反,我只看到了身体的蓝色背景。如果我删除溢出,我可以看到文本字段,但它是不可选的,如果用固定值替换100%,我会看到一个绿色的框,但同样文本字段不可选。
可能是组件div没有显示,因为当使用100%时,它的w/h为0。有人知道这是为什么吗?这也是我无法输入任何文本的原因。
谢谢
发布于 2014-03-12 12:58:53
所以问题是我们重写了onSizeChanged方法,并且没有调用super.调用Super.onSizeChanged(w,h,oldw,oldh)修复了这个问题。感谢您的所有投入
https://stackoverflow.com/questions/22257116
复制相似问题