I have an image (ImageView) on my screen. The image takes up roughly half of the screen which means that you can click both on the image and on the side of the image.
How to I get the x -and y coordinates on the screen when I click on the image?
I tried using onTouchEvent but it is only called when I click outside of the image, not when I click on the image.
Regards,
Mattias
解决方案imageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
int[] values = new int[2];
view.getLocationOnScreen(values);
Log.d("X & Y",values[0]+" "+values[1]);
}
});
Also, this answer of mine will be useful as well.