Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Compensate for screen offset due to menus/toolbars?
    text
    copied!<p>MotionEvent.getRawX/.getRawY return absolute coordinates (i.e. based on the entire screen). But the View receiving that MotionEvent may be (probably is) a child of yet another View, which itself may be at some offset on the screen, etc.</p> <p>In particular, I'm experimenting with a basic app right now and the Android menu/tool bar (with the clock, etc.) is visible at the top of the screen. When I call .getRawX/.getRawY, I get accurate X/Y coordinates for the display as a whole - but how do I determine how those relate to the View's position on the screen if there can be menus, or if the (grand)parent view(s) are themselves smaller than the screen and offset from its edges?</p> <p>Right now, if I use the return values from .getRawX/.getRawY to reposition the View, they work but the View "jumps" down by the height of the menu(s) at the top of the screen because the "absolute" Y value is essentially increased by the vertical offset of the parent View due to the menus above it. Thus there needs to be a general case approach for determining where the parent View(s) are in the absolute coordinates of the screen, so that the raw X/Y values can be adjusted before being used to reposition the View in question.</p> <p>I'm not bothering to post code because it's basically a duplicate of every other example of "move a View by touch" on this and many other websites. I don't have a bug I'm trying to find... I'm looking for the way to relate MotionEvent's absolute coordinates with the relative coordinates of any app that isn't running 100% full screen.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload