I try to read the screen size b开发者_运维问答y using DeviceMetrics, but it gives me the scaled size, not the actual screen size.
How can I read the actual screen size in compatibility mode?
For example, the application runs on a 480x800 screen.
But it gives me 400x700, because of the compatiblility mode.try this code:
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;
}
note: because of the method getRealSize
you might need to catch NoSuchMethodError
Exception
精彩评论