【问题标题】:Programmatically determine the coordinates of a view(Button) in android?以编程方式确定android中视图(按钮)的坐标?
【发布时间】:2012-09-09 13:09:49
【问题描述】:

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

【问题讨论】:

标签: android


【解决方案1】:

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

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

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

【讨论】:

  • 它在数组的两个项目中始终显示 0 值。你能帮我解决这个问题吗?
【解决方案2】:

尝试查看 getLocationInWindow 和 getLocationOnScreen 方法。

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

【讨论】:

    【解决方案3】:

    Here is the solution 。请查看链接以了解视图的屏幕位置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-04
      • 1970-01-01
      • 2011-08-23
      • 2015-10-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多