我尝试使用DeviceMetrics读取屏幕大小,但它给出了缩放的大小,而不是实际的屏幕大小。
如何在兼容模式下阅读实际屏幕尺寸?
例如,应用程序在480x800屏幕上运行 但由于兼容模式,它给了我400x700。
答案 0 :(得分:0)
试试这段代码:
if (Build.VERSION.SDK_INT >= 11) {
Point point= new Point();
getWindowManager().getDefaultDisplay().getRealSize(point);
screenWidth = point.x;
screenHeight = point.y;
} else {
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
screenWidth = displayMetrics.widthPixels;
screenHeight = displayMetrics.heightPixels;
}
注意:由于方法getRealSize
,您可能需要捕获NoSuchMethodError
异常