Blankj / Blankj/AndroidUtilCode

AdaptScreenUtils横屏时适配问题

Offen
#1,716 0 Kommentare 0 Reaktionen 1 zugewiesene Person Beansprucht von @Blankj Auf GitHub ansehen
bug
Vorherrschende Sprache
Java
Sterne
33.6k
Forks
10.6k
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

## 描述 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

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.