I’m expecting that width of window with will be the same with width of the physical screen.
On my Galaxy Nexus width of screen is 720 pixels, but width of window is 360.
Why? What’s wrong? The full code of page:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>My Page</title>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" />
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
$(function() {
windowWidth = $(window).width();
windowHeight = $(window).height();
alert("width: " + windowWidth + " height: " + windowHeight);
});
</script>
</head>
<body id="bo">
</body>
</html>
By default, the
WebViewin Android will assume your web page is targeting a medium density device, and thus, it will scale things accordingly.From the documentation (see the section titled Building web pages to support different screen densities):
So, since the Galaxy Nexus is an
xhdpidevice, theWebViewwill apply 2x scaling to your content, thus resulting in a width of 360.You can change this if you want to, it requires the addition of a
<meta>tag in your HTML. For example, adding the following to your markup should result in an accurate width:However, be aware that you will need to take densities into account in that case.