Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autosize在华为P40多窗口下失效 #347

Open
5 tasks done
SweetSun1993 opened this issue Mar 22, 2021 · 3 comments
Open
5 tasks done

autosize在华为P40多窗口下失效 #347

SweetSun1993 opened this issue Mar 22, 2021 · 3 comments

Comments

@SweetSun1993
Copy link

SweetSun1993 commented Mar 22, 2021

Environment

  • Autosize Version: me.jessyan:autosize:1.1.2
  • Target Android Version: Android 10
  • Device Model: Huawei p40
  • Device Resolution: 1080px * 2340px
  • Design Size On AndroidManifest: design_width_in_dp = 730dp,高度并未设置

Bug Description:

三方应用口袋故事在华为P40多窗口模式下,字体显示异常。
口袋故事使用的是autosize库,当前设置:

且调整design_width_in_dp的值,在多窗口模式下显示字体大小未发生变化,得出结论,autosize未生效。

Log:

AutoSize.java 290行,setDensity方法中
DisplayMetrics activityDisplayMetrics = activity.getResources().getDisplayMetrics();
setDensity(activityDisplayMetrics, density, densityDpi, scaledDensity, xdpi);
这行对于activity.getResources()的DisplayMetrics未生效

根因:
Android源码中getDisplayMetrics是ResourcesImpl中持有的mMetrics对象,华为EMUI代码中针对多窗口做了兼容性修改,在多窗口中返回的并非是ResourcesImpl中持有的mMetrics,而是其copy对象。直接修改copy对象中的属性无法生效。

Screenshot

Related Code:

能否在设置density的时候通过updateConfiguration接口确保更新
样例代码DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
        int ratio = configuration.densityDpi / (int)displayMetrics.density;
        displayMetrics.density += 0.1f;
        Configuration configuration = getResources().getConfiguration();
        configuration.densityDpi = (int) (displayMetrics.density * ratio);
        getResources().updateConfiguration(configuration,displayMetrics);

### Others:
@CaiHong9225
Copy link

我也发现了这个问题,在多窗口的车机上,无法修改density 。

@JessYanCoding
Copy link
Owner

JessYanCoding commented Jul 6, 2021

试试覆盖 getResources 返回一个经过代理的 Resources 对象给 View对象,让 View 中拿到的 mMetrics 对象和 setDensity 的 mMetrics 对象是用一个

#1 (comment)

@wx962464
Copy link

@SweetSun1993 最后此问题则呢么解决处理的?可否提供下思路或者示例代码

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants