UIView具有以下内容:
- convertPoint:toView:
- convertPoint:fromView:
- convertRect:toView:
- convertRect:fromView:
什么是Android等价物?更一般地,给定两个
View
,我如何在第一个View
的坐标系中得到第二个ojit_code的rect? 最佳答案
我认为sdk中没有等效的功能,但是您似乎可以使用getLocationOnScreen
轻松编写自己的实现:
public static Point convertPoint(Point fromPoint, View fromView, View toView){
int[] fromCoord = new int[2];
int[] toCoord = new int[2];
fromView.getLocationOnScreen(fromCoord);
toView.getLocationOnScreen(toCoord);
Point toPoint = new Point(fromCoord[0] - toCoord[0] + fromPoint.x,
fromCoord[1] - toCoord[1] + fromPoint.y);
return toPoint;
}
public static Rect convertRect(Rect fromRect, View fromView, View toView){
int[] fromCoord = new int[2];
int[] toCoord = new int[2];
fromView.getLocationOnScreen(fromCoord);
toView.getLocationOnScreen(toCoord);
int xShift = fromCoord[0] - toCoord[0];
int yShift = fromCoord[1] - toCoord[1];
Rect toRect = new Rect(fromRect.left + xShift, fromRect.top + yShift,
fromRect.right + xShift, fromRect.bottom + yShift);
return toRect;
}
关于android - Android相当于UIView的convertRect/convertPoint函数是什么?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31578204/