Advertisement Jump to content
Sign in to follow this  

Android NDK touch coordinates

This topic is 1857 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, I have a question.


I'm currently trying to get touch to work on Android using the NDK with the android_native_app_glue. 


When I get a touch event, the coordinates seem to be divided by two. So what should be 1100 on the x is being returned as 550.

I've tried multiplying the getPrecision functions on to the returned value from AMotionEvent_getRawX and it's still the same.

Anyone have any ideas as to what may be causing it?


Share this post

Link to post
Share on other sites

That's actually interesting, it was based on what the initial size of the screen that I was given by the device. I honestly have no idea what the resolution should be. All I know is that when I create a screen and resize it to be 1920x1080, my coordinates are coming in 550. Here's a print of what my touch information is:








Share this post

Link to post
Share on other sites

Okay, after a fair bit of searching; the issue is that the screen was using density pixels, (dp), which are a relative coordinate. If you add this line to your manifest: 

	<supports-screens android:anyDensity="true" />

Then it will no longer apply the DPI conversion and your touch coordinates will come in a screen pixels.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!