如何取得一个 View 在屏幕中上的 Rect

/** * Get the boundary of a view in screen coordinates. * 类似 Windows SDK 中的 GetWindowRect + ClientToScreen * @param v * @param r The result. */ private void getRectInScreen(View v, Rect r) { final int w = v.getWidth(); final int h = v.getHeight(); r.left = v.getLeft(); r.top = v.getTop(); r.right = r.left + w; r.bottom = r.top + h; ViewParent p = v.getParent(); while(p instanceof View) { v = (View)p; p = v.getParent(); r.left += v.getLeft(); r.top += v.getTop(); r.right = r.left + w; r.bottom = r.top + h; } }

 

你可能感兴趣的:(windows)