/**
* 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;
}
* 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;
}
}
本文介绍了一种方法,用于获取Android中视图在屏幕坐标系下的边界位置。该方法类似于Windows SDK中的GetWindowRect结合ClientToScreen的功能,通过递归遍历视图及其父视图来计算最终坐标。
1万+

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



