【问题标题】:Touch is within getBounds() of Drawable触摸在 Drawable 的 getBounds() 内
【发布时间】:2023-03-24 08:55:02
【问题描述】:

我有一堂课,我这样设置界限:

tattoo.setBounds(getWidth() / 2 - zoomController - x, getHeight() / 2 - zoomController - y, getWidth()/ 2 + zoomController - x, getHeight()/ 2 + zoomController - y);
tattoo.draw(c);

我希望能够在用户在这些范围内单击时执行操作。检查点击是否在范围内的最简单方法是什么?

【问题讨论】:

    标签: android drawable surfaceview touch-event bounds


    【解决方案1】:

    使用描述drawable 边界的Rect 并在其上调用contains(int x, int y) 方法,传入x 和y 触摸坐标。例如:

    Rect bounds = tattoo.getBounds();
    int x = ...
    int y = ...
    boolean withinBounds = bounds.contains(x, y);
    

    或者,您可以创建自己的(静态)辅助方法;数学真的很基础。 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-10
      • 2010-11-02
      • 2011-10-01
      • 1970-01-01
      相关资源
      最近更新 更多