java–android .getTop()返回0.0

java–android .getTop()返回0.0,第1张

概述我正在开发一个Android锁屏应用程序.我从另一个线程得到了一个想法,检查手指按下的坐标与我设置的图像按钮的坐标.我试图使用.getTop()和.getLeft()来获取图像按钮的坐标,但两者都返回0.0(因为它们是浮点数,而不是int).为什么是这样?我是android开发新手,很抱歉,如果我遗漏了一些

我正在开发一个Android锁屏应用程序.我从另一个线程得到了一个想法,检查手指按下的坐标与我设置的图像按钮的坐标.

我试图使用.gettop()和.getleft()来获取图像按钮的坐标,但两者都返回0.0(因为它们是浮点数,而不是int).

为什么是这样?我是androID开发新手,很抱歉,如果我遗漏了一些明显的东西.

另外,我在某处读到.gettop()在setContentVIEw(R.layout.layoutname)之后无法工作,但如果我把它放在setContentVIEw(…)之上,那么应用程序崩溃了.

有没有其他方法来获取图像按钮的坐标,或者更好/更容易获得表格单元格的坐标和边界?我该怎么办?

提前致谢 :)

解决方法:

您需要将视图添加到布局并显示(至少必须运行一个布局过程和度量过程.).此外,如此获得的坐标是相对于视图的直接父级.

It is possible to retrIEve the location of a vIEw by invoking the
methods getleft() and gettop(). The former returns the left, or X,
coordinate of the rectangle representing the vIEw. The latter returns
the top, or Y, coordinate of the rectangle representing the vIEw.
These methods both return the location of the vIEw relative to its
parent. For instance, when getleft() returns 20, that means the vIEw
is located 20 pixels to the right of the left edge of its direct
parent.

总结

以上是内存溢出为你收集整理的java – android .getTop()返回0.0全部内容,希望文章能够帮你解决java – android .getTop()返回0.0所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1107222.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存