What is the difference between Rect and RectF in the Android SDK?
Asked
Active
Viewed 2.2k times
2 Answers
55
Using Rect
you define its edges using integers and using RectF
they are defined as floats.
Looking at them more carefully I have spotted a few differences actually. I will only list what one implementation has more compared to the other one.
Rect
- equals(Object obj) (for some reason it has its own implementation of equals)
- exactCenterX()
- exactCenterY()
- flattenToString()
- toShortString()
- unflattenFromString(String str)
RectF
So apparently there are some differences.

Octavian Helm
- 39,405
- 19
- 98
- 102
-
Yep one is defined with int http://developer.android.com/reference/android/graphics/Rect.html the other with float http://developer.android.com/reference/android/graphics/RectF.html. a part form that I don't know of any difference which begs the question why create 2 separate classes for that ^^ – Jason Rogers Feb 06 '11 at 13:52
-
@JasonRogers I agree that it is somewhat funny. – Octavian Helm Feb 06 '11 at 13:59
-
I actually went to check the documentation to see if one didn't inherit the other with a bit of casting but not even that lol – Jason Rogers Feb 06 '11 at 14:01
-
@JasonRogers apparently there are some differences! I have listed them in my answer. – Octavian Helm Feb 06 '11 at 14:14