【问题标题】:How can I work with coordinates in android if devices have different screen sizes?如果设备的屏幕尺寸不同,我如何在 android 中使用坐标?
【发布时间】:2014-08-22 08:35:55
【问题描述】:

我正在开发这款安卓 2D 游戏,您必须在其中射击一些敌人。假设我想在坐标 X=250 和 Y=250 中放置一个位图。在我的模拟器中,这正是屏幕的中间,但在其他设备中则不是。如何设置,使我的位图位置与每个设备保持一致?

我已经尝试了方法:“canvas.getWidth()”,但它只适用于 canvas 方法。

希望你能理解。谢谢。

【问题讨论】:

    标签: android coordinates


    【解决方案1】:

    你可以在你的活动中使用这样的东西:

    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int center_x = size.x/2;
    int center_y = size.y/2;
    

    在此处获取有关屏幕尺寸的更多信息:Get screen dimensions in pixels

    【讨论】:

      猜你喜欢
      • 2023-04-02
      • 1970-01-01
      • 2013-07-19
      • 1970-01-01
      • 2023-03-31
      • 2015-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多