查看this答案
如果您的API级别> 13如果您正在活动中,请尝试此操作
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
如果您不在活动中,则可以通过WINDOW_SERVICE获取默认的显示:
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
getWidth和getHeight适用于API级别13或更低
UPDATE
对于API 17和更高版本的方法,Display.getRealSize()返回屏幕的完整大小,如in documentation所述:
Gets the real size of the display
without subtracting any window decor or applying any compatibility
scale factors.
The size is adjusted based on the current rotation of the display.
The real size may be smaller than the physical size of the screen when
the window manager is emulating a smaller display (using adb shell am
display-size).