2

When reading the getX() and getY() values for a series of onTouch events, I find that the ACTION_MOVE events will return the ACTION_DOWN coordinates until a certain distance threshold from these coordinates has been passed. From then onwards the correct coordinates will always be returned.

Steps to reproduce:

  1. Create a new application project with a default activity
  2. Add the following method to the default activity:

    @Override  
    public boolean onTouchEvent(MotionEvent event) {  
        Log.i("getXYDelay", "(x,y)=("+event.getX() + "," + event.getY() + ")");  
        return super.onTouchEvent(event);  
    }  
    
  3. Run on a device and watch logcat as you touch and drag

You should see that, on every touch and drag, the getX()/getY() results only start changing after your finger has moved half a centermeter or so, and from then on it is accurate.

I can see how for a lot of circumstances this would be helpful, but it causes issues in the application that I'm writing, so:

  • Is this initial lag over-ridable? Or can it be bypassed?
  • Is it device specific?

Ideally I'd like to turn it off for a single OpenGL surface view.

Note:

  • It doesn't happen when I use a Samsung Note SPen.
  • The same happens with getRawX()/getRawY().
  • This doesn't happen on an emulator so is presumably coming from the hardware touch drivers.

Update: I'm assuming this is caused by hardware drivers or a similar level, and as such is beyond the application's control. I've also attempted to post this to the android developer group, but after several weeks it seems the moderators are still sitting on my post.

tomrozb
  • 25,773
  • 31
  • 101
  • 122
Kev
  • 33
  • 6
  • Could this be related to the [ViewConfiguration](http://developer.android.com/reference/android/view/ViewConfiguration.html) Specifically the TouchSlop? – pjco Sep 15 '14 at 05:48
  • I think you're right @pjco, thanks for putting a name to it! After a quick search it seems that it's not possible to modify the TouchSlop, I'll do a deeper search when I get a chance, but I think this question is a duplicate of other TouchSlop modification questions. Thanks. – Kev Sep 18 '14 at 09:01

2 Answers2

2

The difference between getX() and getRawX() is,

getRawX() and getRawY() that is guaranteed to return absolute coordinates, relative to the device screen.

While getX() and getY(), should return you coordinates, relative to the View, that dispatched them.

Also, the problem that you are facing, is because of following reason

Layout of the contents of a window happens after all the elements are constructed and added to their parent views. It has to be this way, because until you know what components a View contains, and what they contain, and so on, there's no sensible way you can lay it out.

So you are getting delay.

Rohit
  • 2,646
  • 6
  • 27
  • 52
  • This doesn't relate to when the views are constructing as this happens following every `ACTION_DOWN`, long after construction. (Thanks for the formatting edit) – Kev Jun 10 '14 at 12:34
  • @Kev: Getting delay, I experienced I replied (mentioned in bold). Still you are facing problem then try to post code what you did, we will try to sort it out. :) – Rohit Jun 11 '14 at 03:49
0

i have found a workaround and you can find it here:

Amit Bhatiya
  • 2,621
  • 1
  • 12
  • 20
MaInStReAm
  • 57
  • 2