我想实现这个方法:
//#OnTouchEvent()
public boolean onTouchEvent(MotionEvent event) {
//Coordinates of the touch
int x = (int) event.getX();
int y = (int) event.getY();
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
// Check if the touch is within the coordinates of an image
if x isBetweenCoordinatesXofTheImage
if y isBetweenCoordinatesYofTheImage
//DoSomething
else
//DoNothing
break;
case MotionEvent.ACTION_MOVE:
//nothing
break;
case MotionEvent.ACTION_UP:
//check if the touch is within the coordinates of an image;
if x is betweenCoordinatesX of the image
y is betweenCoordinatesYofTheImage
//DoSomething
else
//DoNothing
break;
}
return true;
}
ImageView 有 4 个角,我需要知道 4 个坐标 (x,y) 才能进行检查。左上角与左下角具有相同的 X 坐标,右上角与右下角具有相同的 X 坐标。对于 Y 坐标是相似的。我的问题是:如何获得 ImageView 的 4 个坐标?
谢谢大家!!!