[英]how to get the view coordinate related to screen?
我有一个View
,它给了我对其父屏幕的坐标。 我已经尝试过getTop()
和getLeft()
的视图方法,但仍然对我不起作用。 我需要主屏幕的坐标?
尝试使用View.getLocationOnScreen()
或getLocationInWindow()
。
例如:
int loc[] = { 0, 0 };
View.getLocationOnScreen(loc);
int x = loc[0]; // x position
int y = loc[1]; // y position
尝试这个,
int[] location = new int[2]; // must be array of two integer.
view.getLocationOnScreen(location);
xAxis = location[0]; //
yAxis = location[1];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.