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;