ooh
V2EX  ›  问与答

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

  •  
  •   ooh · Oct 24, 2020 · 1401 views
    This topic created in 2119 days ago, the information mentioned may be changed or developed.
    今天做模拟点击碰到一个问题,有个游戏界面按钮只能靠坐标进行点击,我想适配不同屏幕,但是在不同分辨率坐标转换上遇到问题,不知道有没有什么公式能转换
    2 replies    2020-10-24 18:31:36 +08:00
    Chemist
        1
    Chemist  
       Oct 24, 2020 via iPhone
    转成百分比再乘回去试试
    ooh
        2
    ooh  
    OP
       Oct 24, 2020
    @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)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1158 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 23:29 · PVG 07:29 · LAX 16:29 · JFK 19:29
    ♥ Do have faith in what you're doing.