我们如何获得顶部带有缺口的屏幕尺寸 [英] How can we get the size of screen with notch on the top

查看:100
本文介绍了我们如何获得顶部带有缺口的屏幕尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有些设备如华为p20(运行android 8,8.1),其顶部具有内置的缺口
当前获取屏幕大小的方法是

There are some devices such as Huawei p20(running android 8,8.1) which has in-built notch on the top. The current way to get the size of the screen is

 Display display = getWindow().getWindowManager().getDefaultDisplay();
 Point screenSize = new Point();

 display.getRealSize(screenSize);
 //screenSize.x
//screenSize.y

领先屏幕外的游戏。因此,有什么方法可以解决Android P和Pre-p设备的缺口问题。

And it's leading the game out of screen. So, is there any way to solve notch issue with android P and Pre-p devices.

推荐答案

只有少数具有 notch 选项的android设备,

There are only few android devices with notch options and currently it is not possible to get exact screen size of such devices using Android APIs.

但是有解决方法,您可以检查设备的名称并相应地调整布局。

BUT there is a work around, you can check the name of device and adjust your layout accordingly.

有一个流行的Android库可以获取Android设备的市场名称。在此处查看更多信息: https://github.com/jaredrummler/AndroidDeviceNames

There is one popular Android library to get the market name of an Android device. Check more information here : https://github.com/jaredrummler/AndroidDeviceNames

如何使用此库:

String deviceName = DeviceName.getDeviceName();

希望这将帮助您专注于开发而不是浪费时间!

Hope this will help you to focus on your development instead of wasting time!

这篇关于我们如何获得顶部带有缺口的屏幕尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆