android density px dp sp

The logical density of the display. This is a scaling factor for the Density Independent Pixel unit, where one DIP is one pixel on an approximately 160 dpi screen (for example a 240x320, 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 .75; etc.

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).

在大约dpi是160的屏幕上,1 dpi= 1px ,所以 density = dpi/160


用DisplayMetrics 获取得到的一些值

		DisplayMetrics m = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(m);
		
		float density = m.density;  //1.5 
		int dDpi = m.densityDpi; //The screen density expressed as dots-per-inch.
		int hpx = m.heightPixels;//The absolute height of the display in pixels. 
		int wpx = m.widthPixels;//
		float sd = m.scaledDensity;//A scaling factor for fonts displayed on the display. This is the same as density, except that it may be adjusted in smaller increments at runtime based on a user preference for the font size. 
		float xdpi = m.xdpi; //The exact physical pixels per inch of the screen in the X dimension. 
		float ydpi = m.ydpi;
 联想 a750 测试结果

08-06 12:23:39.710: I/WhatEverTest(4395): density:1.5
08-06 12:23:39.710: I/WhatEverTest(4395): dDpi:240
08-06 12:23:39.710: I/WhatEverTest(4395): hpx:800
08-06 12:23:39.710: I/WhatEverTest(4395): wpx:480
08-06 12:23:39.710: I/WhatEverTest(4395): sd:1.5
08-06 12:23:39.710: I/WhatEverTest(4395): xdpi:240.0
08-06 12:23:39.710: I/WhatEverTest(4395): ydpi:240.0





你可能感兴趣的:(android density px dp sp)