I want to implement this method:
//#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;
}
An ImageView has 4 coorners and I need to know the 4 coordinates (x,y) to do the check before.
The upper left corner has the same X-coordinate as the lower left and upper right will have the same X coordinate to the lower right. for Y coordinates is similar.
My problem is: how I can obtain the 4 coordinates of a ImageView?
THANKS for all!!!
Just a small question:
Why not set the ImageView itself a touch listener?
If that’s not an options then try:
After you’ll call this method the array will contain the upper left coordinate of your view.
To get the other coordinates just use the height and width of the view:
Make sure those three methods are called only AFTER the view has drawn on the screen – (invoking them in the onCreate will return 0 to all values).