Blankj / Blankj/AndroidUtilCode

AdaptScreenUtils横屏时适配问题

Abierto
#1,716 0 comentarios 0 reacciones 1 asignado Reclamado por @Blankj Ver en GitHub
bug
Lenguaje dominante
Java
Estrellas
33.6k
Forks
10.6k
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.