AndroidUtilCode icon indicating copy to clipboard operation
AndroidUtilCode copied to clipboard

在EMUI和鸿蒙OS的小窗模式下,使用AdaptScreenUtils的屏幕适配方案会导致UI显示异常

Open cooaer opened this issue 3 years ago • 7 comments

描述 Bug

在EMUI和鸿蒙OS的小窗模式下,使用AdaptScreenUtils的屏幕适配方案会导致UI显示异常,使用pt作为单位的UI元素会变得非常大。

  • AndroidUtilCode 的版本:1.29.0
  • 出现 Bug 的设备型号:华为Mate 20、华为P40、荣耀V40
  • 设备的 Android 版本:鸿蒙2.0.0

demo中使用屏幕适配方案页面的截图

正常使用: image 悬浮窗模式下: image

cooaer avatar Jun 23 '21 08:06 cooaer

同样遇到这个问题

bytebubbles avatar Aug 19 '21 02:08 bytebubbles

直接弃用了

ehuiz avatar Nov 04 '21 07:11 ehuiz

遇到相同问题,有解决办法了吗

tangwanchao avatar Jan 04 '22 11:01 tangwanchao

@Blankj @bytebubbles @cooaer

测试机型:荣耀 20 经过如下更改正常工作

`override fun getResources(): Resources {
    var resources = super.getResources()
    resources = AdaptScreenUtils.adaptWidth(resources, 375)
    // 适配后,如果 xdpi 和 fontScale 不是我们想要的,我们修改他并更新
    resources.apply {
        val xdpi = this.getWantXdpi()
        val conf = this.configuration
        val displayMetrics = this.displayMetrics
        if (conf.fontScale != 1.0f || displayMetrics.xdpi != xdpi) {
            if(conf.fontScale != 1.0f){
                conf.fontScale = 1.0f
            }
            if(displayMetrics.xdpi != xdpi){
                displayMetrics.xdpi = xdpi
            }
            @Suppress("DEPRECATION")
            this.updateConfiguration(conf, displayMetrics)
        }
    }
    return resources
}

 private fun Resources.getWantXdpi(): Float {
    return this.displayMetrics.widthPixels * 72f / 375f
}`

tangwanchao avatar Jan 13 '22 10:01 tangwanchao

试了一下,@tangwanchao 的方法没有问题。

lyxxman avatar May 24 '22 06:05 lyxxman

@Blankj @bytebubbles @cooaer

测试机型:荣耀 20 经过如下更改正常工作

`override fun getResources(): Resources {
    var resources = super.getResources()
    resources = AdaptScreenUtils.adaptWidth(resources, 375)
    // 适配后,如果 xdpi 和 fontScale 不是我们想要的,我们修改他并更新
    resources.apply {
        val xdpi = this.getWantXdpi()
        val conf = this.configuration
        val displayMetrics = this.displayMetrics
        if (conf.fontScale != 1.0f || displayMetrics.xdpi != xdpi) {
            if(conf.fontScale != 1.0f){
                conf.fontScale = 1.0f
            }
            if(displayMetrics.xdpi != xdpi){
                displayMetrics.xdpi = xdpi
            }
            @Suppress("DEPRECATION")
            this.updateConfiguration(conf, displayMetrics)
        }
    }
    return resources
}

 private fun Resources.getWantXdpi(): Float {
    return this.displayMetrics.widthPixels * 72f / 375f
}`

@tangwanchao 牛啊铁汁,给你个么么哒(*  ̄3)(ε ̄ *)

bytebubbles avatar May 24 '22 07:05 bytebubbles

@Blankj @bytebubbles @cooaer

测试机型:荣耀 20 经过如下更改正常工作

`override fun getResources(): Resources {
    var resources = super.getResources()
    resources = AdaptScreenUtils.adaptWidth(resources, 375)
    // 适配后,如果 xdpi 和 fontScale 不是我们想要的,我们修改他并更新
    resources.apply {
        val xdpi = this.getWantXdpi()
        val conf = this.configuration
        val displayMetrics = this.displayMetrics
        if (conf.fontScale != 1.0f || displayMetrics.xdpi != xdpi) {
            if(conf.fontScale != 1.0f){
                conf.fontScale = 1.0f
            }
            if(displayMetrics.xdpi != xdpi){
                displayMetrics.xdpi = xdpi
            }
            @Suppress("DEPRECATION")
            this.updateConfiguration(conf, displayMetrics)
        }
    }
    return resources
}

 private fun Resources.getWantXdpi(): Float {
    return this.displayMetrics.widthPixels * 72f / 375f
}`

@tangwanchao 老哥稳,太牛了

SSSSunrise avatar Mar 02 '23 06:03 SSSSunrise