Reputation: 10659
How to get image coordinates at mouse hover position.
Please let me know
Thank you
Upvotes: 1
Views: 2204
Reputation: 305
Try this
http://developer.android.com/reference/android/view/View.OnHoverListener.html
Available from api 14.
Upvotes: 0
Reputation: 2408
You set an onTouchListener for the image, and in the onTouch event, you can pull the x,y coordinates out of the MotionEvent. getX and getY will get you the x and y coordinates in relation to the image, and getRawX and getRawY will get the x,y coordinates of the screen.
public boolean onTouch(View arg0, MotionEvent arg1) {
System.out.println("X: "+arg1.getX());
System.out.println("Y: "+arg1.getY());
System.out.println("Raw X: "+arg1.getRawX());
System.out.println("Raw Y: "+arg1.getRawY());
return true;
}
Upvotes: 2
Reputation: 3817
As stakx said, Android doesn't support the mouse. However, if you are referring to the image that currently has focus, try this:
Image focusedImg = getViewById(R.id.YourMainLayout).findFocus();
int[] relativeToParentPixels = { focusedImg.getLeft(), focusedImg.getTop(),
focusedImg.getRight(), focusedImg.getBottom() };
Now you'll have the boundary positions of the image in an array.
Upvotes: 0
Reputation: 84735
Quoted from the "android-porting" mailing list (end of August 2010):
Android currently doesn't support mouse input, so has no concept of mouse hover.
Upvotes: 3