检索X'放大器;一个按钮,在Android的Y坐标?放大器、坐标、按钮、Android

2023-09-07 10:43:56 作者:情感防御

我一直工作在Android上一段时间,想知道是否有可能获取在Android的一个按钮的位置。

I've been working on Android for a while and would like to know if it is possible to retrieve the position of a button in android.

我的目标是让X'放大器; Y坐标,并打印出来的logcat中。

My target is to get the X & Y coordinates and print them on the LOGCAT.

一些例子来告诉我怎么会是AP preciated。

Some example to show me how would be appreciated.

感谢

推荐答案

当然,你可以得到这些,确保意见得出ATLEAST一次,然后再尝试得到的位置。你可以尝试在onResume(位置),并尝试这些功能

Sure, you can get these, make sure the views are drawn atleast once before you try to get the positions. You could try to get the positions in onResume() and try these functions

view.getLocationInWindow()
or
view.getLocationOnScreen()

如果你neeed的东西相对于父,用

or if you neeed something relative to the parent, use

view.getLeft(), view.getTop()

链接到API定义:

Links to API definitions:

getLocationInWindow getLocationOnScreen getLeft 共达 getLocationInWindow getLocationOnScreen getLeft getTop