0
  • 在你的 Presentation 或副屏 Activity 里输出一下以下的日志看看?


    DisplayMetrics metrics = new DisplayMetrics();
    display.getMetrics(metrics);
    
    
    Log.d("DualScreen", "副屏 densityDpi=" + metrics.densityDpi
            + " widthPixels=" + metrics.widthPixels
            + " heightPixels=" + metrics.heightPixels
            + " density=" + metrics.density);
    


    如果是dpi的问题,可以在你的Presentation修改一下上下文的dpi,dpi影响dp转实际的px


    private Context createFixedContext(Context outerContext, Display display) {
        DisplayMetrics dm = new DisplayMetrics();
        display.getMetrics(dm);
    
    
        Resources res = outerContext.getResources();
        Configuration config = res.getConfiguration();
    
    
        // clone 一份
        DisplayMetrics newMetrics = new DisplayMetrics();
        newMetrics.setTo(dm);
    
    
        // 替换 density,让 dp 正常换算
        float density = (float) dm.widthPixels / 1920f; // 1920 是你的设计稿宽度
        newMetrics.density = density;
        newMetrics.scaledDensity = density;
        newMetrics.densityDpi = (int) (density * 160);
    
    
        Resources newRes = new Resources(res.getAssets(), newMetrics, config);
        return new ContextWrapper(outerContext) {
            @Override
            public Resources getResources() {
                return newRes;
            }
        };
    }
    


    调用一下:


    public SecondaryDisplay(Context outerContext, Display display, LifecycleOwner owner) {
        super(createFixedContext(outerContext, display), display);
        this.parent = outerContext;
        this.owner = owner;
    }
    


    1153952789488054272  评论     打赏       拉大锯
    • 没做过双屏的,你可以贴一下代码和图片吗?图片上传点击上传按钮。不要直接粘贴。

      1153952789488054272  评论     打赏       拉大锯
      • 橘浩  回复 @拉大锯
        已经更新
        橘浩 2025-09-30 16:30   回复 1374278154541199360
    相关问题
    后会有期 · Nuxt
    2025-10-01 09:11 15 6
    下雨天像 · 找工作 / 面试题
    2025-08-10 17:31 23 16
    资质平平 · Android
    2025-02-20 09:14 117 100
    尖沙咀-段坤 · 项目
    2025-01-06 23:39 38 2
    雅澤yaduo · 领券联盟
    2025-01-03 20:39 88 50
    呆瓜小董 · webview
    2024-11-30 18:02 100 20
    阿肥 · 鸿蒙next
    2024-10-25 18:07 47 100
    尖沙咀-段坤 · 安卓
    2024-09-11 11:03 48 2
    YanLQ · AOSP
    2024-08-10 11:57 59 100
    断点 · vue
    2024-08-08 10:05 110 30