首先处理 WindowManager
WindowManager mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
然后就能得到数据了
方法 2
// get screen dimensions in pixels
Display display = mWindowManager.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
方法 1
// get screen dimensions in pixels
DisplayMetrics displaymetrics = new DisplayMetrics();
mWindowManager.getDefaultDisplay().getMetrics(displaymetrics);
int width = displaymetrics.widthPixels;
int height = displaymetrics.heightPixels;