gpt4 book ai didi

android - 来自 getLocationOnScreen/getLocationInWindow 的坐标不正确

转载 作者:IT老高 更新时间:2023-10-28 13:25:13 26 4
gpt4 key购买 nike

getLocationOnScreen()getLocationInWindow() 的调用都给了我一个 top/Y 坐标约为 30px (status/通知栏的高度)太低了。 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;

关于android - 来自 getLocationOnScreen/getLocationInWindow 的坐标不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2638342/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com