How to get screen cordinates corresponding to the whole screen, and not the View touched?

老子叫甜甜 提交于 2019-11-29 09:17:46

MotionEvent class has getX() and getY() methods which return the coordinates relative to the view, as you have discovered.

However it also has getRawX() and getRawY() methods, which according to the docs say:

Returns the original raw X (or Y) coordinate of this event. For touch events on the screen, this is the original location of the event on the screen, before it had been adjusted for the containing window and views.

Sounds like this is what you're after.

Vikram

Try using this after view loaded on screen.

int[] location = new int[2];
View.getLocationOnScreen(location); 
Log.v(Common.TAG,"left: "+ location[0]);
Log.v(Common.TAG,"top: "+ location[1]);
slayton

Get the View's location on the screen, then you can calculate the rest using simply arithmetic. How to get the absolute coordinates of a view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!