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?
Well, that can be of help to you: http://developer.android.com/reference/android/view/MotionEvent.html
I suppose the values are the center of the blob or area of the touch. Remember that it can be a tool like a mouse or a stylus so the area will be more precise. It has methods and constants for the supposed area of the finger that is touching.
The link has so many methods about that question, that I will not copy and paste, as its pretty documented, so I think you need to read it.
Some of then:
getPressure()
getSize()
getPointerCount()
getXPrecision()
About the returned value, the section Device Types will give plenty of information.
Some relevant ones:
The interpretation of the contents of a MotionEvent varies significantly depending on the source class of the device.
On pointing devices with source class SOURCE_CLASS_POINTER such as touch screens, the pointer coordinates specify absolute positions such as view X/Y coordinates. Each complete gesture is represented by a sequence of motion events with actions that describe pointer state transitions and movements.
On joystick devices with source class SOURCE_CLASS_JOYSTICK, the pointer coordinates specify the absolute position of the joystick axes. The joystick axis values are normalized to a range of -1.0 to 1.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With