对于正常使用,您可以使用 DisplayMetrics 类并获得“可渲染”尺寸,但我想计算出实际的物理屏幕尺寸,其中包括虚拟按钮高度。
在我的 Galaxy Nexus 上,无论我尝试什么,报告的尺寸都是 1196x720,我可以用什么来获得 1280x720 的物理尺寸? Nexus 7、Nexus 4 和 Nexus 10 设备也是如此。
更新:这是我现在使用的最终代码,包括修复:
//Activity A = this;
DisplayMetrics displayMetrics = new DisplayMetrics();
WindowManager wm = (WindowManager) A.getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
Display disp = wm.getDefaultDisplay();
int API_LEVEL = android.os.Build.VERSION.SDK_INT;
if (API_LEVEL >= 17)
{
disp.getRealMetrics(displayMetrics);
}
else
{
disp.getMetrics(displayMetrics);
}
int Width = displayMetrics.widthPixels;
int Height = displayMetrics.heightPixels;
最佳答案
你应该使用 Display.getRealSize(Point)来自官方文档 here
The display area is described in two different ways.
The application display area specifies the part of the display that may contain an application window, excluding the system decorations.
The application display area may be smaller than the real display area because the system subtracts the space needed for decor elements such as the status bar. Use the following methods to query the application display area: getSize(Point), getRectSize(Rect) and getMetrics(DisplayMetrics).
The real display area specifies the part of the display that contains content including the system decorations. Even so, the real display area may be smaller than the physical size of the display if the window manager is emulating a smaller display using (adb shell am display-size). Use the following methods to query the real display area: getRealSize(Point), getRealMetrics(DisplayMetrics).
关于android - 如何在 Android 中获取屏幕尺寸,包括虚拟按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16503064/