在android中以编程方式确定视图(按钮)的坐标?

在android中以编程方式确定视图(按钮)的坐标?,android,Android,如何以编程方式确定android中视图的坐标(位置)? 我的xml文件中有一个按钮。如何在java代码中确定该按钮的坐标?获取java代码中的视图引用 Integer [] location = new Integer[]; view.getLocationOnScreen(location); 现在,整数数组包含屏幕上视图的坐标。尝试查看getLocationInWindow和getLocationOnScreen方法 http://developer.android.com/r

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

获取java代码中的视图引用

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

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

尝试查看getLocationInWindow和getLocationOnScreen方法


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

。请查看该链接以了解视图的屏幕位置。

请查看此链接:它始终在数组的两个项目中显示0值。你能帮我吗。