【问题标题】:Get X and Y point within bitmap using OnTouchListener使用 OnTouchListener 获取位图中的 X 和 Y 点
【发布时间】:2013-04-24 01:59:28
【问题描述】:

我在屏幕上放置了一个位图,并且想要制作它,以便当您触摸该位图上的某个点时,会发生特定于该点的事情。为此,我需要它,以便在触摸位图上的某个点时返回位图上该点的 x 和 y。

例子

我想要这样,如果你触摸他的二头肌,二头肌就会弹出,如果你触摸他的胸部,胸部就会弹出这个词。

我需要这个才能在不同尺寸的屏幕上工作。

提前致谢

【问题讨论】:

  • 如果您有任何发现,请分享答案。

标签: android bitmap coordinates imagemap ontouchlistener


【解决方案1】:

假设您的图片位于名为 bitmapImageView 中。

bitmap.setOnTouchListener(new OnTouchListener{
@Override
public boolean onTouch(View v, MotionEvent ev){
    float x = ev.getX(); //the most recent x coordinate of the touch
    float y = ev.getY(); //the most recent y coordinate of the touch
}
});

除此之外,使用透明矩形区域覆盖您的图像可能更容易,这些区域充当交互按钮,在触摸时显示文本。这样你就不需要处理屏幕坐标和你想要的图像坐标之间潜在的坐标不匹配了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-25
    相关资源
    最近更新 更多