Activity中:
第一种方法:
WindowManager windowManage = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
第二种方法:
WindowManager windowManager = getWindowManager();
Display display = windowManager.getDefaultDisplay();
Point outSize = new Point();
display.getSize(outSize); //这个方法minAPI 13
int width = outSize.x;
int height = outSize.y;
第三种方法:
DisplayMetrics metric = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metric);
int width = metric.widthPixels;
int height = metric.heightPixels;
网友评论