英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论