Blankj / Blankj/AndroidUtilCode

AdaptScreenUtils横屏时适配问题

Open
#1,716 0 comments 0 reactions 1 assignee Claimed by @Blankj View on GitHub
bug
Dominant language
Java
Stars
33.6k
Forks
10.6k
PR merge metrics
No merged PRs in 30d

Description

## 描述 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分辨率获取到的差不多是这个值
![image](https://user-images.githubusercontent.com/39788948/200981345-4fd288d2-433f-4e4d-81e1-d5e777fc01ad.png)

上述设备中获取到的值为
![image](https://user-images.githubusercontent.com/39788948/200981369-7b6828dc-cfdd-4f63-8998-842c281217b2.png)

两者之间的值分别为:
![image](https://user-images.githubusercontent.com/39788948/200981447-731b8b1e-2e49-478f-ae2e-953f306379f9.png)

所以猜测
resources.getDisplayMetrics().widthPixels 获取的值是正常竖屏的宽度的

同理自定义的 CustomAdaptScreenUtils 中 对于adaptWidth 方法里头的值做出方向判断后再决定获取对应的width/height

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.