0

如何以编程方式确定android中视图的坐标(位置)?我在我的 xml 文件中放置了一个按钮。如何在 java 代码中确定该按钮的坐标?

4

3 回答 3

1

这是解决方案。请检查链接以找出视图的屏幕位置。

于 2012-09-17T10:28:13.570 回答
0

获取 java 代码中的视图引用。

   Integer [] location = new Integer[];
   view.getLocationOnScreen(location);

现在整数数组包含屏幕上视图的坐标。

于 2012-09-17T10:20:13.760 回答
0

尝试查看 getLocationInWindow 和 getLocationOnScreen 方法。

http://developer.android.com/reference/android/view/View.html#getLocationInWindow(int[])

于 2012-09-17T10:23:43.590 回答