前言,我写到后面发现这里有个帖子不错;http://www.miui.com/thread-413844-1-1.htmlhtml
因此大家能够选择不向下看了!java
在reference/android/util/DisplayMetrics.html中有如何得到Metrics(即屏幕显示信息,如大小啊密度啊)的代码。android
以下 :app
DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics);
dpi:dots per inch,每英寸中的像素数.ide
xdpi:即水平方向每英寸中的像素数,ui
ydpi:即垂直方向每英寸的像素数.this
关于xdpi,ydpi,android参考中是这样介绍的: xdpi:The exact physical pixels per inch of the screen in the X demension. 即,屏幕在X方向上每英寸中精确的物理像素。 ydpi:The exact physical pixels per inch of the screen in the Y dimension.
dip,dp;device independent pixel.设置独立像素.spa
density:这个东西将dip和dpi联系在一块儿了!翻译
参见android中的文档 :docs/reference/android/util/DisplayMetrics.htmlcode
density是显示的逻辑密度,是用于设备独立像素(dip)的扩展因子,在一个160dpi的屏幕里,一个像素几乎就等于一个dip.
(例如,一个240*320,1.5寸宽,2.0寸长 的的屏幕),它提供了系统显示基线.所以在一个160dpi的屏幕上这个密度值是1.
在一个120dpi的屏幕中将是0.75.
即公式出来了:density = dpi/160;
原文:
The logical density of the display.This is a scaling factor for the Density Independent Pixel unit,where one DIP is is one pixel on an approximately 160 dpi screen(for example a 240*320,1.5"x2" screen),providing the baseline of the system's display,Thus on a 160dpi screen this density value will be 1; on a 120 dpi screen it would be 0.75;etc.这个值并不彻底等同于真空屏幕的尺寸(由xdpi和ydpi给定,可是用于在屏幕dpi增大的时候扩展整个UI的尺寸,例如,一个240
x320的屏幕将拥有密度值为1,而无论它的宽度只有1.8寸,1.3寸等等.)然而,若是屏幕的分辨率增长到320x480而这个屏幕的尺寸依然是1.5寸x2寸.那么密度将增长(大概到1.5)(译注:这个仍是翻译得很差的,有些地方没有怎么看明白!)
原文:
This value does not exactly follow the real screen size(as given by xdpi and ydpi,but rather is used to scale the size of the overall UI in steps based on gross changes in the display dpi.For example,a 240x320 screen will have a density of 1 even if its width is 1.8",1.3",etc,However,if the screen resolution is increased to 320x480 but the screen size remained 1.5"x2" then the density would be increased(probably to 1.5)
关于这个android中尺寸的值请参见:
docs/guide/topics/resources/more-resources.html#Dimension
下面是一个asus平板的输出的metrics信息:
1.03-20 11:09:49.240:metrics={xdpi:160.15764,ydpi:160.0,width:800,height:1232,density:1.0}
2.使用默认模拟器WVGA800
03-20 03:15:32.282: I/ClientStation(280): metrics={xdpi:240.0,ydpi:240.0,width:480,height:800,density:1.5}
3.这个仍是使用默认的模拟器,可是分辨率被我设置成了:800x1232
03-20 03:35:25.006: I/ClientStation(337): metrics={xdpi:240.0,ydpi:240.0,width:800,height:1232,density:1.5}
4.一个更详细点的数据,默认的模拟器:
03-20 05:58:32.369: I/Demo(584): metrics={xdpi:240.0,ydpi:240.0,width:480,height:800,density:1.5,densityDpi:240,widthPixels: 800}
5. asus
03-20 14:04:23.702: I/Demo(13824): metrics={xdpi:160.15764,ydpi:160.0,width:800,height:1232,density:1.0,densityDpi:160,widthPixels: 1232}