一个调用 getLocationOnScreen将()
或 getLocationInWindow()
这两个给我一个顶/ Y
坐标大约〜30像素(状态/通知栏的高度)太远了。该左/ X
的坐标是死的。
A call to getLocationOnScreen()
or getLocationInWindow()
both give me a top/Y
coordinate that is about ~30px (status/notifications bar's height) too far down. The left/X
coordinate is dead on.
正如我上面暗示,我相信不同的是状态/通知栏的,因为......我可能是错的。我想我可以解决这个问题,如果我能决定的通知栏的大小,但是,我无法这样做。
As I hinted above, I believe the difference is because of the status/notification bar... I could be wrong. I think I can solve this if I can determine the size of the notification bar but, I'm having trouble doing just that.
任何帮助将是很大的AP preciated。
Any help would be greatly appreciated.
我最终通过判断状态/通知栏的高度像解决这个问题,所以:
I ended up solving this issue by determining the height of the status/notification bar like so:
View globalView = ...; // the main view of my activity/application
DisplayMetrics dm = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(dm);
int topOffset = dm.heightPixels - globalView.getMeasuredHeight();
View tempView = ...; // the view you'd like to locate
int[] loc = new int[2];
tempView.getLocationOnScreen(loc);
final int y = loc[1] - topOffset;