我们如何获得顶部带有缺口的屏幕尺寸
有些设备如华为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!