查找屏幕是否有圆角 [英] Find if screen has rounded corners

查看:66
本文介绍了查找屏幕是否有圆角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来确定Android设备是否具有带圆角的屏幕以及理想的半径.

I am looking for a way to determine whether Android device has screen with rounded corners and ideally also the radius.

我的用例是一个包含单个全屏OpenGL视图的游戏.它在边缘和边框附近渲染了一些UI元素,以便为游戏本身提供尽可能多的区域.但是,当屏幕具有圆角时,它们将被部分隐藏,因此需要以不同的方式放置.

My usecase is a game that consist of a single fullscreen OpenGL view. It renders some UI elements close to the edges and borders to give as much area as possible to the game itself. But when the screen has rounded corners, they would be partially hidden, so they need to be positioned differently.

推荐答案

当前(2018年5月7日),您只能使用

Currently (7th May, 2018) you can only check if the physical screen is rounded or not (for Android Wear) using isRounded() method BUT can not check if screen corners are rounded.

我认为只有少数带有圆角的设备.因此,最好只检查设备名称并相应地调整布局.

I think there are only a few devices with rounded corners out there. So it's better to just 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 here for more information: https://github.com/jaredrummler/AndroidDeviceNames

用法:

String deviceName = DeviceName.getDeviceName();

希望此替代方法可以为您提供暂时的帮助.

Hope this workaround will help you temporarily.

也许将来所有设备都将带有圆角屏幕(假设).

Maybe all devices in the future will release with round corner screens (just an assumption).

更新(2019年6月6日)

Android正式支持在运行Android的设备上显示抠图 9(API级别28)及更高版本.

Android officially supports display cutouts on devices running Android 9 (API level 28) and higher.

Referecne: https://developer.android.com/guide/topics/display -cutout

Referecne : https://developer.android.com/guide/topics/display-cutout

这篇关于查找屏幕是否有圆角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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