Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Motionevent.getX and getY

I need help understanding the following.

Say I have a display that is 854x480 pixels. Why is it that the MotionEvent.getX and getY methods return floats? As far as I can tell, the pixels on the display are discrete integers, there is no such thing as a half a pixel on the display.

like image 260
Andi Jay Avatar asked Sep 03 '10 22:09

Andi Jay


People also ask

What is Action_up and Action_down?

It doesn't mean a gesture like swipe down it means that user touched the screen (finger down, the touch or gesture just started). Now you need to catch MotionEvent.ACTION_UP (finger up, gesture or touch ends here) and decide if there was a gesture you need. http://developer.android.com/training/gestures/detector.html.

Which motion event does a gesture start with?

A gesture starts with a motion event with ACTION_DOWN that provides the location of the first pointer down. As each additional pointer that goes down or up, the framework will generate a motion event with ACTION_POINTER_DOWN or ACTION_POINTER_UP accordingly.

What is motion event?

Motion Event Explanation Motion events describe movements in terms of an action code and a set of axis values. The action code specifies the state change that occurred such as a pointer going down or up. The axis values describe the position and other movement properties.

How do you make a motion event on android?

Use the getPointerId(int) method to obtain a pointer id to track pointers across motion events in a gesture. Then for successive motion events, use the findPointerIndex(int) method to obtain the pointer index for a given pointer id in that motion event.


1 Answers

From the developer page:

"Returns the X coordinate of this event for the given pointer index (use getPointerId(int) to find the pointer identifier for this index). Whole numbers are pixels; the value may have a fraction for input devices that are sub-pixel precise."

http://developer.android.com/reference/android/view/MotionEvent.html#getX()

So for some devices the touch screen may be more precise than just pixel resolution. I would imagine this would be the case the majority of the time for low density devices such as the Droid Eris.

To picture it easier, think of the touchscreen as being completely independent of the screen; like how you can have a drawing tablet of one size that works independently of screen resolution. Say if your resolution is 1600x1200, moving your pen say .02 inches might be the equivalent of 4 or 5 pixels of movement, whereas on an 800x600 screen it would be only 2 or 3. (completely made up numbers, but the point is valid)

like image 153
Kevin Coppock Avatar answered Nov 16 '22 03:11

Kevin Coppock