获取手机屏幕的分辨率(尺寸):
方式一
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
float density = dm.density;
float xdpi = dm.xdpi;
float ydpi = dm.ydpi;
Log.d(TAG, "手机密度=================:" + density);
Log.d(TAG, "PX:手机像素分辨率宽width:" + width + "PX:手机像素分辨率宽height:" + height);
Log.d(TAG, "手机xdpi:" + xdpi + "手机ydpi:" + ydpi);
方式二: Display display = getWindowManager().getDefaultDisplay();
Point point = new Point();
display.getSize(point);
int x = point.x;
int y = point.y;
// int height = display.getHeight(); API13 之前 (弃用)
// int width = display.getWidth();
// Log.d(TAG, "手机像素宽width:" + width + "手机像素宽height:" + height);
Log.d(TAG, "PX:手机像素分辨率宽x:" + x + "手机像素宽y:" + y);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
float density = dm.density;
float xdpi = dm.xdpi;
float ydpi = dm.ydpi;
Log.d(TAG, "手机密度=================:" + density);
Log.d(TAG, "PX:手机像素分辨率宽width:" + width + "PX:手机像素分辨率宽height:" + height);
Log.d(TAG, "手机xdpi:" + xdpi + "手机ydpi:" + ydpi);
方式二:
Display display = getWindowManager().getDefaultDisplay();
Point point = new Point();
display.getSize(point);
int x = point.x;
int y = point.y;
// int height = display.getHeight(); API13 之前 (弃用)
// int width = display.getWidth();
// Log.d(TAG, "手机像素宽width:" + width + "手机像素宽height:" + height);
Log.d(TAG, "PX:手机像素分辨率宽x:" + x + "手机像素宽y:" + y);