什么是android相当于UIView的convertRect / convertPoint函数?

UIView具有以下内容
- convertPoint:toView:
- convertPoint:fromView:
- convertRect:toView:
- convertRect:fromView:

什么是Android相当的?更一般地说,给定两个视图,我如何得到第二个View的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 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性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...