本文介绍了Android的web视图 - JavaScript的屏幕尺寸与实际对比屏幕尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的活动具有以下布局...

I have a very simple Activity with the following layout...

<LinearLayout xmlns:android="http://schemas.android.com/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.

所以......我的HTC Desire,该的WebView 的理论占据800×480(宽x高)像素。所有优秀的,到目前为止,它不完全充满整个屏幕。

So...on my HTC Desire, the WebView in theory is occupying 800x480 (wxh) pixels. All good so far, it DOES fill the screen totally.

的困惑我的是,的WebView 加载一个HTML文件,从它使用一个JavaScript函数来获取屏幕宽度和高度的服务器...

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>

...问题是, screenW 527和 screenH 是320,我不明白为什么

...the problem is that screenW is 527 and screenH is 320 and I don't understand why.

看着320的高度,这正是三分之二的480,所以我又看了看什么三分之二的800(〜533)。所以,看起来既 screen.width screen.height 中的JavaScript是报告三分之二的实际像素可用。

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?

推荐答案

有关的网站,你可以在你的网站使用元标签控制在Android的屏幕尺寸。

For website you can control the screen size in android using a meta tag in your site.

有三种设置为屏幕尺寸低DPI,中等DPI和高DPI。

There are three settings for the "screen" size low-dpi, medium-dpi and high-dpi.

所以,该设备会自动缩放你的网站(它假定中等dpi的,如果你没有设置任何东西)

So the device is automatically scaling your website (it assumes medium-dpi if you didn't set anything)

在JavaScript的你没有得到设备的确切像素大小,你更喜欢的设备是在该地区的某个地方......

In javascript you don't get the exact pixel size of the device, you get more like the device is somewhere in that area...

有一个很好的解释这可以在这里找到: http://developer.android。 COM /引导/ webapps /下targeting.html

A good explanation for this can be found here: http://developer.android.com/guide/webapps/targeting.html

这篇关于Android的web视图 - JavaScript的屏幕尺寸与实际对比屏幕尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 16:28
查看更多