一:
int width =getWindowManager().getDefaultDisplay().getWidth();
int height =getWindowManager().getDefaultDisplay().getHeight();
二、
WindowManager manager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
Point screenResolution = new Point(display.getWidth(), display.getHeight());
Log.i("屏幕长宽", "宽度:"+ screenResolution.x + ",高度:" + screenResolution.y);
三、
Point point =new Point();
getWindowManager().getDefaultDisplay().getSize(point);
Log.i("屏幕长宽", "宽度:"+ point.x + ",高度:" + point.y);
四、
DisplayMetrics displayMetrics =getResources().getDisplayMetrics();
int width = displayMetrics.widthPixels;
int height =displayMetrics.heightPixels;
Log.i("屏幕长宽", "宽度:"+ width + ",高度:" + height + ",所有的信息:" + displayMetrics.toString());
日志信息如下:
宽度:720,高度:1280,所有的信息:DisplayMetrics{density=2.0, width=720, height=1280, scaledDensity=2.0, xdpi=294.967, ydpi=285.193}