检索 X &android中按钮的Y坐标? [英] Retrieve the X & Y coordinates of a button in android?

查看:26
本文介绍了检索 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.

一些例子向我展示如何将被赞赏.

Some example to show me how would be appreciated.

谢谢

推荐答案

当然,你可以得到这些,确保在你尝试获取位置之前至少绘制一次视图.您可以尝试获取 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()

或者如果你需要一些与父相关的东西,使用

or if you need something relative to the parent, use

view.getLeft(), view.getTop()

API 定义链接:

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

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