Android 在ImageView中检测(x,y)接触点

Android 在ImageView中检测(x,y)接触点,android,bitmap,imageview,touch,coordinate-transformation,Android,Bitmap,Imageview,Touch,Coordinate Transformation,我的布局如下: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ff000000"> <ImageView android:id="@+id/img_vie

我的布局如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:background="#ff000000">

<ImageView
    android:id="@+id/img_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerInParent="true"
    android:src="@drawable/ic_launcher" />
</RelativeLayout>

ImageView包含一个位图,我想检测用户触摸位图的点的(x,y)坐标。Loc[0],Loc[1]始终分别为0和76。我认为它们是布局左上角的绝对坐标。绝对的,我是说,就整个屏幕而言。然而,event.getX()和event.getY()似乎是活动标题下方屏幕区域的绝对坐标。对吗?如果是,如何计算触摸点相对于位图的相对坐标

我不理解你的问题,但我想你问的是,
你想知道用户在位图上的什么位置触摸它

我认为你的
x=event.getX()
y=event.getY()
都是对的,试试看

假设位图位于
bx
by
坐标,其宽度和高度为
bw
bh

然后检查您的触摸是否在坐标范围内,即
bx
by


祝你好运

你想要触摸点相对于图像边界的位置,而不是整个屏幕的位置?只需从触摸坐标中减去图像的位置。例如:

int imageRelativeX = event.getX() - loc[0];
int imageRelativeY = event.getY() - loc[1];

然后就是图像的左上角(0,0)和右下角(图像宽度、图像高度)。

请阅读并使用rh ImageView.getImageMatrix()播放,谢谢@pskink。我试图理解如何利用getImageMatrix方法,但不清楚如何继续。你能给我提供更多的细节吗?在快速通过后,我认为一个更详细的解决方案感谢Mayank的评论,但不幸的是,它没有你想象的那么简单。问题在于,位图在渲染到ImageView时会自动重新缩放,将event.getX()和event.getY()返回的绝对坐标转换为位图中的相对坐标并不清晰-(感谢卡万的好意评论。请阅读我的评论,以便回答下面的问题。
int imageRelativeX = event.getX() - loc[0];
int imageRelativeY = event.getY() - loc[1];