Blankj / Blankj/AndroidUtilCode

AdaptScreenUtils横屏时适配问题

Đang mở
#1,716 0 bình luận 0 reaction 1 người được giao Được @Blankj nhận Xem trên GitHub
bug
Ngôn ngữ chính
Java
Star
33.6k
Fork
10.6k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.