DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
float density = dm.density; // 屏幕密度(像素比例:0.75/1.0/1.5/2.0)dpi
int densityDPI = dm.densityDpi; // 屏幕密度(每寸像素:120/160/240/320)dpi
float xdpi = dm.xdpi;
float ydpi = dm.ydpi;
LogUtil.i(TAG, "DisplayMetrics xdpi=" + xdpi + "; ydpi=" + ydpi);
LogUtil.i(TAG, "DisplayMetrics density=" + density + "; " + "densityDPI=" + densityDPI);
int screenWidthPx = dm.widthPixels; // 屏幕寬px
int screenHeightPx = dm.heightPixels; // 屏幕寬 px
LogUtil.i(TAG, "screenWidth px=" + screenWidthPx + "; screenHeight px=" + screenHeightPx);
ip
int screenWidth = (int) (dm.widthPixels / density + 0.5f); // 屏幕寬 dip
int screenHeight = (int) (dm.heightPixels / density + 0.5f); // 屏幕高 dip
LogUtil.i(TAG, "screenWidth dip=" + screenWidth + "; screenHeight dip="+ screenHeight);
get