开发者

how can I get the actual screen size when an application runs in compatibility mode

开发者 https://www.devze.com 2023-04-12 23:19 出处:网络
I try to read the screen size b开发者_运维问答y using DeviceMetrics, but it gives me the scaled size, not the actual screen size.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号