We can get the coordinates of the touch position on the screen using the following functions:
public boolean onTouchEvent(MotionEvent event){
float x_forOnTouch = event.getX();
float y_forOnTouch = event.getY();
What exactly is being returned by the getX()
and getY()
functions? Is it returning pixel values? When a finger touches a screen position, it will probably touch a number of pixels. So what exactly does the function return?
Again, let us suppose that in the area I touch with my finger, there are multiple pixels on the screen, as shown below:
Suppose I need to click and drag the point at pixel 1, but the area my finger touches covers pixel 1 and 2. How do I accurately detect which pixel has been clicked, so that I can click and drag on pixel 1 or 2 when I need it?