I noticed that I can't use Rectangle
in Android Studios because it doesn't support Java 8, but Android has Rect
instead.
All of the tutorials I've seen were for general Java, so they didn't use Android's Rect
.
Are there any major differences between Rect
and Rectangle
or can they be used interchangeably when I code? (Assuming I replace Rectangle
with Rect
, of course.)
NOTE : I'm using them to check for object collision.
答案 0 :(得分:4)
Rectangle is a class from Java 2D API.
Rect (and RectF) is a class from Android Draw API.
Java Rectangles are expressed as (xPos, yPos, width, height).
Android Rects are expressed as (left, top, right, bottom).
You must use the Android one.
To convert from (xywh) to (ltrb) the following is necessary:
Rect = new Rect(x, y, x + w, y + h);