
- 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相当于UIView的convertRect / convertPoint函数?全部内容,希望文章能够帮你解决什么是android相当于UIView的convertRect / convertPoint函数?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)