2015-06-05 119 views
3

如果我有5英寸对角线屏幕尺寸和2.3英寸屏幕宽度的Android设备,并且它的屏幕支持1080 * 1920像素,那么屏幕密度最接近的类型是什么?如何解决这个问题?Android中的像素密度

回答

1

你可以找出设备显示器信息从活动

DisplayMetrics dm = new DisplayMetrics(); 
getWindowManager().getDefaultDisplay().getMetrics(dm); 

int dpi = dm.densityDpi; 

dm.densityDpi阅读DisplayMetrics会给你点每英寸

你可以ALS表示设备DPI桶Ø得到其他显示指标,如:

float density  - The logical density of the display - scaling factor 
float scaledDensity - A scaling factor for fonts displayed on the display. 
int widthPixels  - The absolute width of the display in pixels. 
int heightPixels - The absolute height of the display in pixels. 
float xdpi   - Physical pixels per inch of the screen in the X dimension. 
float ydpi   - Physical pixels per inch of the screen in the Y dimension. 

但是,对于某些设备xdpiydpi度量返回错误的号码,你不能依靠他们。由于API 17,您也可以使用getRealMetrics()。它应该给你准确的值xdpiydpi

DisplayMetrics dm = new DisplayMetrics(); 
getWindowManager().getDefaultDisplay().getRealMetrics(dm);