2015-06-05 53 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);