安卓的DisplayMetrics返回的屏幕尺寸像素值不正确。

huangapple go评论89阅读模式
英文:

Android DisplayMetrics returns incorrect screen size in pixels

问题

我有一台三星Galaxy S20+。

我运行这段代码:

    DisplayMetrics displayMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    mScreenHeight = displayMetrics.heightPixels;
    mScreenWidth = displayMetrics.widthPixels;

我得到的结果是:

mScreenHeight = 2201.0
mScreenWidth = 1080.0

然而,根据这个页面,S20+的屏幕分辨率是1440x3200。

如此巨大的差距不仅仅是状态栏的高度问题。

我该如何获得真实的屏幕像素尺寸?

谢谢!

英文:

I have a Samsung Galaxy S20+.

I run this code:

DisplayMetrics displayMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    mScreenHeight = displayMetrics.heightPixels;
    mScreenWidth = displayMetrics.widthPixels;

I get:

mScreenHeight = 2201.0
mScreenWidth = 1080.0

Whereas the S20+ screen resolution is 1440x3200 according to this page.

Such a big gap is not just a question of status bar height.

How can I get the real screen size in pixels ?

Thanks !

答案1

得分: 1

近期的 Galaxy S 设备有一个可以改变屏幕分辨率的设置。在 S20+ 上有三个选项:

  • WQHD+:3200x1440
  • FHD+:2400x1080
  • HD+:1600x720

你很可能处于 FHD+ 模式。尽管设备的真实像素尺寸为 3200x1440,但你可用的软件窗口被降低了,这就是 DisplayMetrics 对象所给出的内容。

英文:

Recent Galaxy S devices have a setting to change the screen resolution.
On the S20+ there are 3 options:

  • WQHD+: 3200x1440
  • FHD+: 2400x1080
  • HD+: 1600x720

You're likely in the FHD+ mode. Even though the device has a real pixel dimension of 3200x1440, your usable software window is downscaled and this is what the DisplayMetrics object is giving you.

huangapple
  • 本文由 发表于 2020年9月11日 23:02:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/63849639.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定