admin管理员组文章数量:1391937
I have a very simple Activity with the following layout...
<LinearLayout xmlns:android=""
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</WebView>
</LinearLayout>
The Activity
itself is set for full screen (no title bar and no Android notification bar) and forced to landscape.
So...on my HTC Desire, the WebView
in theory is occupying 800x480 (wxh) pixels. All good so far, it DOES fill the screen totally.
The confusion I have is that the WebView
loads an HTML document from a server which uses a javascript function to get the screen width and height...
<script type="text/javascript">
<!--
function getDims() {
var screenW = screen.width;
var screenH = screen.height;
return "size=" + screenW + "x" + screenH;
};
-->
</script>
...the problem is that screenW
is 527 and screenH
is 320 and I don't understand why.
Looking at a height of 320, it's exactly two-thirds of 480 so I then looked at what two-thirds of 800 is (~533). So it seems both screen.width
and screen.height
in the javascript are reporting two-thirds of actual pixels available.
Can anyone explain why this is happening?
I have a very simple Activity with the following layout...
<LinearLayout xmlns:android="http://schemas.android./apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</WebView>
</LinearLayout>
The Activity
itself is set for full screen (no title bar and no Android notification bar) and forced to landscape.
So...on my HTC Desire, the WebView
in theory is occupying 800x480 (wxh) pixels. All good so far, it DOES fill the screen totally.
The confusion I have is that the WebView
loads an HTML document from a server which uses a javascript function to get the screen width and height...
<script type="text/javascript">
<!--
function getDims() {
var screenW = screen.width;
var screenH = screen.height;
return "size=" + screenW + "x" + screenH;
};
-->
</script>
...the problem is that screenW
is 527 and screenH
is 320 and I don't understand why.
Looking at a height of 320, it's exactly two-thirds of 480 so I then looked at what two-thirds of 800 is (~533). So it seems both screen.width
and screen.height
in the javascript are reporting two-thirds of actual pixels available.
Can anyone explain why this is happening?
Share Improve this question asked Dec 25, 2011 at 8:33 SquonkSquonk 48.9k19 gold badges107 silver badges136 bronze badges1 Answer
Reset to default 4For website you can control the screen size in android using a meta tag in your site.
There are three settings for the "screen" size low-dpi, medium-dpi and high-dpi.
So the device is automatically scaling your website (it assumes medium-dpi if you didn't set anything)
In javascript you don't get the exact pixel size of the device, you get more like the device is somewhere in that area...
A good explanation for this can be found here: http://developer.android./guide/webapps/targeting.html
本文标签: Android Webviewjavascript screen dimensions vs actual screen dimensionsStack Overflow
版权声明:本文标题:Android Webview - javascript screen dimensions vs actual screen dimensions - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744749258a2623074.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论