检索X'放大器;一个按钮,在Android的Y坐标? [英] Retrieve the X & Y coordinates of a button in android?

查看:107
本文介绍了检索X'放大器;一个按钮,在Android的Y坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直工作在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:

  • <一个href="http://developer.android.com/reference/android/view/View.html#getLocationInWindow%28int%5B%5D%29">getLocationInWindow
  • <一个href="http://developer.android.com/reference/android/view/View.html#getLocationOnScreen%28int%5B%5D%29">getLocationOnScreen
  • getLeft
  • 共达
  • getLocationInWindow
  • getLocationOnScreen
  • getLeft
  • getTop

这篇关于检索X'放大器;一个按钮,在Android的Y坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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