V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
ooh
V2EX  ›  问与答

Android 屏幕上某一点坐标在不同分辨率下是否有公式进行转换。

  •  
  •   ooh · 2020-10-24 18:09:34 +08:00 · 920 次点击
    这是一个创建于 1291 天前的主题,其中的信息可能已经有所发展或是发生改变。
    今天做模拟点击碰到一个问题,有个游戏界面按钮只能靠坐标进行点击,我想适配不同屏幕,但是在不同分辨率坐标转换上遇到问题,不知道有没有什么公式能转换
    2 条回复    2020-10-24 18:31:36 +08:00
    kyuuseiryuu
        1
    kyuuseiryuu  
       2020-10-24 18:18:19 +08:00 via iPhone
    转成百分比再乘回去试试
    ooh
        2
    ooh  
    OP
       2020-10-24 18:31:36 +08:00
    @kyuuseiryuu 比如下面这俩屏幕,我需要匹配的区域在 2280x1080 和 2220x1080 这俩发分辨率下是面积一样大的,但是第一块屏幕比第二块屏幕长

    2020-10-24 17:13:20.043 24838-24838/com.example I/System.out: DisplayMetrics{density=3.0, width=1080, height=2060, scaledDensity=3.0, xdpi=435.428, ydpi=432.179, densityDpi=480, noncompatWidthPixels=1080, noncompatHeightPixels=2060, noncompatDensity=3.0, noncompatDensityDpi=480, noncompatXdpi=435.428, noncompatYdpi=432.179}屏幕大小(1080, 2280)
    2020-10-24 17:31:46.073 27690-27690/com.example I/System.out: DisplayMetrics{density=2.625, width=1080, height=2094, scaledDensity=2.8875, xdpi=386.3655, ydpi=388.8825}屏幕大小(1080, 2220)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3187 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 00:34 · PVG 08:34 · LAX 17:34 · JFK 20:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.