前言,我寫到後面發現這裏有個帖子不錯;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}