我注意到我不能Rectangle在 Android Studios 中使用,因为它不支持 Java 8,但 Android 支持Rect。
我看过的所有教程都是针对通用 Java 的,所以他们没有使用 Android 的Rect.
当我编码时,它们之间有什么主要区别Rect,Rectangle或者它们可以互换使用吗?(假设我替换Rectangle用Rect,当然)。
注意:我正在使用它们来检查对象碰撞。
Rectangle 是来自 Java 2D API 的一个类。
Rect(和 RectF)是来自 Android Draw API 的一个类。
Java 矩形表示为 (xPos, yPos, width, height)。
Android Rects 表示为(左、上、右、下)。
您必须使用 Android 之一。
要将 (xywh) 转换为 (ltrb),需要执行以下操作:
Rect = new Rect(x, y, x + w, y + h);
| 归档时间: |
|
| 查看次数: |
1582 次 |
| 最近记录: |