AndroidUtilCode
AndroidUtilCode copied to clipboard
AdaptScreenUtils横屏时适配问题
描述 Bug
横屏时 resources.getDisplayMetrics().widthPixels 获取的值是正常竖屏的宽度的
- AndroidUtilCode 的版本:1.31.0
- 出现 Bug 的设备型号:huawei mate40/mate 50Pro 均为鸿蒙3
- 设备的 Android 版本:api 31
相关代码 (customAdapt 是我本地临时规避问题的类)
val orientation = Resources.getSystem().configuration.orientation
return if (orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
CustomAdaptScreenUtils.adaptWidth(oldResource, 360)
} else {
CustomAdaptScreenUtils.adaptWidth(oldResource, 640)
}
截图
正常情况下 同为2k分辨率获取到的差不多是这个值

上述设备中获取到的值为

两者之间的值分别为:

所以猜测 resources.getDisplayMetrics().widthPixels 获取的值是正常竖屏的宽度的
同理自定义的 CustomAdaptScreenUtils 中 对于adaptWidth 方法里头的值做出方向判断后再决定获取对应的width/height