2

I've created an OnTouchListener for motion events in an activity, and I want to find where they happen relative to the screen.

I can use event.getRawX() to find the x co-ordinate, and similarly windowManager.getDefaultDisplay().getMetrics(new DisplayMetrics()) or ...getSize(new Point()) to get the display dimensions.

The problem I'm having is that the display dimensions are consistently reporting the width as 1080, but the motionevents I receive return numbers greater than 1800 for getRawX().

Using the deprecated display.getWidth() returns something close, around 1700 - but even this is lower than what's reported at the right edge of the screen.

I assume motion events use a different co-ordinate system to the display metrics - but how can I convert between the two?

Cheers

Nic

Mihriban Minaz
  • 3,043
  • 2
  • 32
  • 52
shinyford
  • 29
  • 10
  • 1
    Did you mean "... I receive return numbers greater than *1080* for ..." ? –  Jan 08 '19 at 14:21

1 Answers1

0

So, I have an answer. This is down to my own stupidity.

What I forgot to mention is that I am viewing the screen in landscape mode. Using v.getWidth(), rather than the display dimension, returns 1920, which makes much more sense.

So obviously (with hindsight) the view width takes into account the orientation, which the display width doesn't - so I've been reading the portrait width (1080) rather than the landscape width/portrait height (1920).

Goodness knows what display.getWidth() was returning...

Thanks to anyone who read and thought about this, and Mihriban for reformatting it.

shinyford
  • 29
  • 10