致电getLocationOnScreen()
or getLocationInWindow()
都给我一个top/Y
坐标大约~30px(状态/通知栏的高度)太低了。这left/X
坐标完全正确。
正如我上面所暗示的,我相信差异是因为状态/通知栏......我可能是错的。我想如果我可以确定通知栏的大小我就可以解决这个问题,但是我在这样做时遇到了困难。
任何帮助将不胜感激。
我最终通过确定状态/通知栏的高度解决了这个问题,如下所示:
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;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)