Android Guides | Samples

Android.Graphics.Rect Class

Rect holds four integer coordinates for a rectangle.

See Also: Rect

Syntax

[Android.Runtime.Register("android/graphics/Rect", DoNotGenerateAcw=true)]
public sealed class Rect : Object, IParcelable, IDisposable

Remarks

Rect holds four integer coordinates for a rectangle. The rectangle is represented by the coordinates of its 4 edges (left, top, right bottom). These fields can be accessed directly. Use width() and height() to retrieve the rectangle's width and height. Note: most methods do not check to see that the coordinates are sorted correctly (i.e. left <= right and top <= bottom).

[Android Documentation]

Requirements

Namespace: Android.Graphics
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1

The members of Android.Graphics.Rect are listed below.

See Also: Object

Public Constructors

Create a new empty Rect.
Create a new rectangle, initialized with the values in the specified rectangle (which is left unmodified).
Create a new rectangle with the specified coordinates.

Public Properties

BottomInt32.
[read-only]
static
CreatorIParcelableCreator.
[read-only]
IsEmptyBoolean. Returns true if the rectangle is empty (left >= right or top >= bottom)
LeftInt32.
RightInt32.
TopInt32.

Protected Properties

[read-only]
override
ThresholdClassIntPtr. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.
[read-only]
override
ThresholdTypeType. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Public Methods

CenterX() : Int32
CenterY() : Int32
Contains(Rect) : Boolean
Returns true iff the specified rectangle r is inside or equal to this rectangle.
Contains(Int32, Int32) : Boolean
Returns true if (x,y) is inside the rectangle.
Contains(Int32, Int32, Int32, Int32) : Boolean
Returns true iff the 4 specified sides of a rectangle are inside or equal to this rectangle. i.e. is this rectangle a superset of the specified rectangle.
DescribeContents() : Int32
Parcelable interface methods
ExactCenterX() : Single
ExactCenterY() : Single
FlattenToString() : String
Return a string representation of the rectangle in a well-defined format.
Height() : Int32
Inset(Int32, Int32)
Inset the rectangle by (dx,dy).
Intersect(Rect) : Boolean
If the specified rectangle intersects this rectangle, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle.
Intersect(Int32, Int32, Int32, Int32) : Boolean
If the rectangle specified by left,top,right,bottom intersects this rectangle, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle.
static
Intersects(Rect, Rect) : Boolean
Returns true iff the two specified rectangles intersect.
Intersects(Int32, Int32, Int32, Int32) : Boolean
Returns true if this rectangle intersects the specified rectangle.
Offset(Int32, Int32)
Offset the rectangle by adding dx to its left and right coordinates, and adding dy to its top and bottom coordinates.
OffsetTo(Int32, Int32)
Offset the rectangle to a specific (left, top) position, keeping its width and height the same.
ReadFromParcel(Parcel)
Set the rectangle's coordinates from the data stored in the specified parcel.
Set(Rect)
Copy the coordinates from src into this rectangle.
Set(Int32, Int32, Int32, Int32)
Set the rectangle's coordinates to the specified values.
SetEmpty()
Set the rectangle to (0,0,0,0)
SetIntersect(Rect, Rect) : Boolean
If rectangles a and b intersect, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle.
Sort()
Swap top/bottom or left/right if there are flipped (i.e. left > right and/or top > bottom).
ToShortString() : String
Return a string representation of the rectangle in a compact form.
static
UnflattenFromString(String) : Rect
Returns a Rect from a string of the form returned by Rect.FlattenToString, or null if the string is not of that form.
Union(Rect)
Update this Rect to enclose itself and the specified rectangle.
Union(Int32, Int32)
Update this Rect to enclose itself and the [x,y] coordinate.
Union(Int32, Int32, Int32, Int32)
Update this Rect to enclose itself and the specified rectangle.
Width() : Int32
WriteToParcel(Parcel, ParcelableWriteFlags)
Write this rectangle to the specified parcel.