不正确协调从getLocationOnScreen将/ getLocationInWindow [英] Incorrect Coordinates From getLocationOnScreen/getLocationInWindow

查看:750
本文介绍了不正确协调从getLocationOnScreen将/ getLocationInWindow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个调用 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;

这篇关于不正确协调从getLocationOnScreen将/ getLocationInWindow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆