android获取UI控件在屏幕上的坐标

1、获取UI控件在屏幕上的坐标

getLocationOnScreen(int []location)

这个int[] 有2个参数,x和y坐标

2、获取UI控件在窗口的坐标

getLocationInWindow(int []location)

用法同上

例如手机屏幕480*800,里面装载了一个scrollView大小为480*1600,此刻滑动到y=1400处有一个UI控件,getLocationOnScreen获取的是[0,1400],而getLocationInWindow获取的是[0,600],是一个相对坐标

3、获取UI控件在父控件里的相对坐标

getLeft()

getRight()

getTop()

getBottom()

原文地址:https://www.cnblogs.com/arthur3/p/3200673.html