/** * 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; } }
如何取得一个 View 在屏幕中上的 Rect
最新推荐文章于 2021-05-25 15:50:52 发布
本文介绍了一种在Android中获取视图边界在屏幕坐标系中的位置的方法,类似于Windows SDK中的GetWindowRect结合ClientToScreen的功能。通过递归遍历视图及其父视图,累积偏移量来确定视图在屏幕上的绝对位置。
3004

被折叠的 条评论
为什么被折叠?



