以英寸声明的大小,并使用DisplayMetrics获得的大小之间的差异 [英] Difference between the declared size in inches and the size obtained using DisplayMetrics

查看:295
本文介绍了以英寸声明的大小,并使用DisplayMetrics获得的大小之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个三星Galaxy S4主动

当我执行在Android上,下code:

When I execute on Android, the following code:

DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width=dm.widthPixels;
int height=dm.heightPixels;
int dens=dm.densityDpi;
double wi=(double)width/(double)dens;
double hi=(double)height/(double)dens;
double x = Math.pow(wi,2);
double y = Math.pow(hi,2);
double screenInches = Math.sqrt(x+y);

我获得

width = 1080
heigh = 1920
dens = 480

那么,是所用的公式是正确的, screenInches 为4.589。但本说明书中说,该screenInches大小为5

So, is the used formula is correct, screenInches is 4.589. But the specification said that the screenInches size is 5.

我也试图与我的三星Galaxy SII 这给了我:

I have also tried with my Samsung Galaxy SII that gives me:

width = 480
heigh = 800
dens = 240

对应于 screenInches 的3.887,而不是4.3(如在规范说的)

that corresponds to a screenInches of 3.887 instead of 4.3 (as said in the specs)

为什么在英寸声明的大小,我得到大小之间这种差异?

Why there is this difference between the declared size in inches and the size I obtain?

修改:看来densityDpi返回这些值之一:(120,160,213,240,320,480或640 DPI)

EDIT: It seems that densityDpi returns one of these values: (120, 160, 213, 240, 320, 480 or 640 dpi).

推荐答案

我不认为你可以从DisplayMetrics.densityDpi真正的屏幕像素密度。它只能返回特定的恒定值之一。
DisplayMetrics文档说,

I don't think that you can get the real screen density from DisplayMetrics.densityDpi. It can return only one of particular constant value. DisplayMetrics documentation says that

屏幕密度EX pressed为点每英寸。可能是DENSITY_LOW,DENSITY_MEDIUM或DENSITY_HIGH。

The screen density expressed as dots-per-inch. May be either DENSITY_LOW, DENSITY_MEDIUM, or DENSITY_HIGH.

但是,<一个href=\"http://static.googleusercontent.com/media/source.android.com/en//compatibility/android-cdd.pdf\"相对=nofollow> Android的兼容性定义文件(CDD)。提供了多个COM prehensive解释

But Android Compatibility Definition Document (CDD). provides a more comprehensive explanation

屏幕像素密度结果
  Android的UI框架定义了一组标准
  逻辑密度,以帮助应用程序开发目标应用程序
  资源。
  设备实现必须报告下列之一
  合乎逻辑的Andr​​oid框架密度通过
  android.util.DisplayMetrics API和必须执行的应用程序
  这个标准密度。
  结果> 120 DPI,被誉为LDPI
  结果> 160 dpi的,被称为MDPI
  结果> 213 dpi的,被称为tvdpi
  结果> 240 dpi的,被称为华电国际
  结果> 320 DPI,被誉为xhdpi
  结果> 400 dpi的,被称为400DPI
  结果> 480 dpi的,被称为xxhdpi
  结果> 640 dpi的,被称为xxxhdpi
  结果
  设备实现应该定义
  标准Android框架密度数值上最接近
  屏幕的物理密度,除非该逻辑密度推
  最低报道如下屏幕尺寸的支持。如果标准
  Android框架密度是数值最接近于物理
  密度的结果在一个屏幕大小是小于最小
  支持兼容的屏幕尺寸(320 DP宽),设备
  实现应该报告下一个最低的标准Android
  骨架密度。

Screen Density
The Android UI framework defines a set of standard logical densities to help application developers target application resources. Device implementations MUST report one of the following logical Android framework densities through the android.util.DisplayMetrics APIs, and MUST execute applications at this standard density.
> 120 dpi, known as 'ldpi'
> 160 dpi, known as 'mdpi'
> 213 dpi, known as 'tvdpi'
> 240 dpi, known as 'hdpi'
> 320 dpi, known as 'xhdpi'
> 400 dpi, known as '400dpi'
> 480 dpi, known as 'xxhdpi'
> 640 dpi, known as 'xxxhdpi'
Device implementations SHOULD define the standard Android framework density that is numerically closest to the physical density of the screen, unless that logical density pushes the reported screen size below the minimum supported. If the standard Android framework density that is numerically closest to the physical density results in a screen size that is smaller than the smallest supported compatible screen size (320 dp width), device implementations SHOULD report the next lowest standard Android framework density.

您可以得到每英寸的网确切的物理像素从的 DespalyMetrics.xdpi DespalyMetrics.ydpi

You can get the exact physical pixels per inch of the screen in the X and Y dimension from DespalyMetrics.xdpi and DespalyMetrics.ydpi

这篇关于以英寸声明的大小,并使用DisplayMetrics获得的大小之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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