I'm making an application that has an image that occupies all ImageView
, and when the user clicks somewhere on that image, the X and Y coordinates corresponding to the image are drawn, and a circle with a center is drawn at that point.
Since my image has the following size (and therefore the ImageView
, which by default in Android, has its size determined by the dimensions of the image):
imgView.width = (int) (screen_width * 0.8);
imgView.height = (int) (screen_heigh * 0.8);
Using the ImageView
imgView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
real_x = (float) (event.getX());
real_y = (float) (event.getY());
//desenhe um círculo com centro em Point(real_x,real_y) na imagem contida no imgView
}
}
The problem is that event.getX()
and event.getY()
do not return the actual coordinates, corresponding to the point clicked on the image. So a conversion is needed ** but how to do this conversion in a way that is valid for any screen size ?? **