"off by one" in Rect sizes

agraham

Expert
Licensed User
Longtime User
I seemed to be suffering from "off by ones" with Rects. The parameters are supposed to specify the top left and bottom right coordinates of the rectangle so silly me expected that

R.Initialise(0, 0, 199, 199)

would specify a 200 x 200 rectangle. However the width and height of the resulting rectangle is 199! The answer was that my expection of the meaning of bottom and right are not those of the Android developers. The clue is this gem from the Android documentation.

The left and top are considered to be inside the rectangle, while the right and bottom are not
 
Top