ICS View.getTop() 不起作用

发布于 2024-12-20 17:54:28 字数 349 浏览 3 评论 0原文

在我的应用程序中,我使用 onTouchEvent()

int y = (int) event.getY() - myView.getTop();

来获取相对于我的视图触摸位置。

问题是在冰淇淋三明治中 myView.getTop() 总是返回 0。

此处不报告任何更改。

我的应用程序在 SDK 版本 << 的情况下工作正常14.

On my App in the onTouchEvent() I use

int y = (int) event.getY() - myView.getTop();

to get the relative to my view touch position.

The problem is that in Ice Cream Sandwich myView.getTop() always returns 0.

Here doesn't report any changes.

My App is working fine with SDK Version < 14.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

墨离汐 2024-12-27 17:54:28

getTop() 报告 View 在其父容器中的 Y 位置。如果 getTop() 返回 0,这意味着您的视图始终位于其父视图的顶部。 event.getY() 已经返回视图坐标系中的位置。

getTop() reports the Y location of a View within its parent container. If getTop() returns 0, this means your view is located all the way at the top of its parent. event.getY() already returns a position in the view's coordinates system.

风铃鹿 2024-12-27 17:54:28

我想你需要使用

int y = (int)myView.getTop() -  event.getY()  ;

I think you ned to use

int y = (int)myView.getTop() -  event.getY()  ;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文