Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Inherited Constants](https://developer.android.com/reference/android/graphics/Rect#inhconstants) \| [Fields](https://developer.android.com/reference/android/graphics/Rect#lfields) \| [Ctors](https://developer.android.com/reference/android/graphics/Rect#pubctors) \| [Methods](https://developer.android.com/reference/android/graphics/Rect#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/graphics/Rect#inhmethods)

# Rect

*** ** * ** ***

` public final class Rect `   
` extends https://developer.android.com/reference/java/lang/Object ` ` implements https://developer.android.com/reference/android/os/Parcelable `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.graphics.Rect |

<br />

*** ** * ** ***

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).

Note that the right and bottom coordinates are exclusive. This means a Rect being drawn untransformed onto a `https://developer.android.com/reference/android/graphics/Canvas` will draw into the column and row described by its left and top coordinates, but not those of its bottom and right.

## Summary

### Inherited constants

From interface `https://developer.android.com/reference/android/os/Parcelable` `int` `https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR`

Descriptor bit used with `https://developer.android.com/reference/android/os/Parcelable#describeContents()`: indicates that the Parcelable object's flattened representation includes a file descriptor.
`int` `https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE`

Flag for use with `https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)`: the object being written is a return value, that is the result of a function such as "`Parcelable someFunction()`", "`void someFunction(out Parcelable)`", or "`void someFunction(inout Parcelable)`".

| ### Fields ||
|---|---|
| ` public static final https://developer.android.com/reference/android/os/Parcelable.Creator<https://developer.android.com/reference/android/graphics/Rect>` | `https://developer.android.com/reference/android/graphics/Rect#CREATOR` <br /> |
| ` public int` | `https://developer.android.com/reference/android/graphics/Rect#bottom` <br /> |
| ` public int` | `https://developer.android.com/reference/android/graphics/Rect#left` <br /> |
| ` public int` | `https://developer.android.com/reference/android/graphics/Rect#right` <br /> |
| ` public int` | `https://developer.android.com/reference/android/graphics/Rect#top` <br /> |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/graphics/Rect#Rect()() ` Create a new empty Rect. |
| ` https://developer.android.com/reference/android/graphics/Rect#Rect(android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect r) ` Create a new rectangle, initialized with the values in the specified rectangle (which is left unmodified). |
| ` https://developer.android.com/reference/android/graphics/Rect#Rect(int,%20int,%20int,%20int)(int left, int top, int right, int bottom) ` Create a new rectangle with the specified coordinates. |

| ### Public methods ||
|---|---|
| ` int` | ` https://developer.android.com/reference/android/graphics/Rect#centerX()() ` |
| ` int` | ` https://developer.android.com/reference/android/graphics/Rect#centerY()() ` |
| ` boolean` | ` https://developer.android.com/reference/android/graphics/Rect#contains(int,%20int,%20int,%20int)(int left, int top, int right, int bottom) ` Returns true iff the 4 specified sides of a rectangle are inside or equal to this rectangle. |
| ` boolean` | ` https://developer.android.com/reference/android/graphics/Rect#contains(android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect r) ` Returns true iff the specified rectangle r is inside or equal to this rectangle. |
| ` boolean` | ` https://developer.android.com/reference/android/graphics/Rect#contains(int,%20int)(int x, int y) ` Returns true if (x,y) is inside the rectangle. |
| ` int` | ` https://developer.android.com/reference/android/graphics/Rect#describeContents()() ` Parcelable interface methods |
| ` boolean` | ` https://developer.android.com/reference/android/graphics/Rect#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object o) ` Indicates whether some other object is "equal to" this one. |
| ` float` | ` https://developer.android.com/reference/android/graphics/Rect#exactCenterX()() ` |
| ` float` | ` https://developer.android.com/reference/android/graphics/Rect#exactCenterY()() ` |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/graphics/Rect#flattenToString()() ` Return a string representation of the rectangle in a well-defined format. |
| ` int` | ` https://developer.android.com/reference/android/graphics/Rect#hashCode()() ` Returns a hash code value for the object. |
| ` int` | ` https://developer.android.com/reference/android/graphics/Rect#height()() ` |
| ` void` | ` https://developer.android.com/reference/android/graphics/Rect#inset(int,%20int,%20int,%20int)(int left, int top, int right, int bottom) ` Insets the rectangle on all sides specified by the insets. |
| ` void` | ` https://developer.android.com/reference/android/graphics/Rect#inset(android.graphics.Insets)(https://developer.android.com/reference/android/graphics/Insets insets) ` Insets the rectangle on all sides specified by the dimensions of `insets`. |
| ` void` | ` https://developer.android.com/reference/android/graphics/Rect#inset(int,%20int)(int dx, int dy) ` Inset the rectangle by (dx,dy). |
| ` boolean` | ` https://developer.android.com/reference/android/graphics/Rect#intersect(int,%20int,%20int,%20int)(int left, int top, int right, int bottom) ` 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. |
| ` boolean` | ` https://developer.android.com/reference/android/graphics/Rect#intersect(android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect r) ` 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. |
| ` boolean` | ` https://developer.android.com/reference/android/graphics/Rect#intersects(int,%20int,%20int,%20int)(int left, int top, int right, int bottom) ` Returns true if this rectangle intersects the specified rectangle. |
| ` static boolean` | ` https://developer.android.com/reference/android/graphics/Rect#intersects(android.graphics.Rect,%20android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect a, https://developer.android.com/reference/android/graphics/Rect b) ` Returns true iff the two specified rectangles intersect. |
| ` boolean` | ` https://developer.android.com/reference/android/graphics/Rect#isEmpty()() ` Returns true if the rectangle is empty (left \>= right or top \>= bottom) |
| ` void` | ` https://developer.android.com/reference/android/graphics/Rect#offset(int,%20int)(int dx, int dy) ` Offset the rectangle by adding dx to its left and right coordinates, and adding dy to its top and bottom coordinates. |
| ` void` | ` https://developer.android.com/reference/android/graphics/Rect#offsetTo(int,%20int)(int newLeft, int newTop) ` Offset the rectangle to a specific (left, top) position, keeping its width and height the same. |
| ` void` | ` https://developer.android.com/reference/android/graphics/Rect#readFromParcel(android.os.Parcel)(https://developer.android.com/reference/android/os/Parcel in) ` Set the rectangle's coordinates from the data stored in the specified parcel. |
| ` void` | ` https://developer.android.com/reference/android/graphics/Rect#set(int,%20int,%20int,%20int)(int left, int top, int right, int bottom) ` Set the rectangle's coordinates to the specified values. |
| ` void` | ` https://developer.android.com/reference/android/graphics/Rect#set(android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect src) ` Copy the coordinates from src into this rectangle. |
| ` void` | ` https://developer.android.com/reference/android/graphics/Rect#setEmpty()() ` Set the rectangle to (0,0,0,0) |
| ` boolean` | ` https://developer.android.com/reference/android/graphics/Rect#setIntersect(android.graphics.Rect,%20android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect a, https://developer.android.com/reference/android/graphics/Rect b) ` If rectangles a and b intersect, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle. |
| ` void` | ` https://developer.android.com/reference/android/graphics/Rect#sort()() ` Swap top/bottom or left/right if there are flipped (i.e. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/graphics/Rect#toShortString()() ` Return a string representation of the rectangle in a compact form. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/graphics/Rect#toString()() ` Returns a string representation of the object. |
| ` static https://developer.android.com/reference/android/graphics/Rect` | ` https://developer.android.com/reference/android/graphics/Rect#unflattenFromString(java.lang.String)(https://developer.android.com/reference/java/lang/String str) ` Returns a Rect from a string of the form returned by `https://developer.android.com/reference/android/graphics/Rect#flattenToString()`, or null if the string is not of that form. |
| ` void` | ` https://developer.android.com/reference/android/graphics/Rect#union(int,%20int,%20int,%20int)(int left, int top, int right, int bottom) ` Update this Rect to enclose itself and the specified rectangle. |
| ` void` | ` https://developer.android.com/reference/android/graphics/Rect#union(android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect r) ` Update this Rect to enclose itself and the specified rectangle. |
| ` void` | ` https://developer.android.com/reference/android/graphics/Rect#union(int,%20int)(int x, int y) ` Update this Rect to enclose itself and the \[x,y\] coordinate. |
| ` int` | ` https://developer.android.com/reference/android/graphics/Rect#width()() ` |
| ` void` | ` https://developer.android.com/reference/android/graphics/Rect#writeToParcel(android.os.Parcel,%20int)(https://developer.android.com/reference/android/os/Parcel out, int flags) ` Write this rectangle to the specified parcel. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.
From interface ` https://developer.android.com/reference/android/os/Parcelable ` ` abstract int` ` https://developer.android.com/reference/android/os/Parcelable#describeContents()() `

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.
` abstract void` ` https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)(https://developer.android.com/reference/android/os/Parcel dest, int flags) `

Flatten this object in to a Parcel.

## Fields

### CREATOR

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final Creator<Rect> CREATOR
```

<br />

<br />

### bottom

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int bottom
```

<br />

<br />

### left

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int left
```

<br />

<br />

### right

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int right
```

<br />

<br />

### top

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int top
```

<br />

<br />

## Public constructors

### Rect

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Rect ()
```

Create a new empty Rect. All coordinates are initialized to 0.

<br />

### Rect

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Rect (Rect r)
```

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

<br />

| Parameters ||
|---|---|
| `r` | `Rect`: The rectangle whose coordinates are copied into the new rectangle. This value may be `null`. <br /> |

### Rect

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Rect (int left, 
                int top, 
                int right, 
                int bottom)
```

Create a new rectangle with the specified coordinates. Note: no range checking is performed, so the caller must ensure that left \<= right and top \<= bottom.

<br />

| Parameters ||
|---|---|
| `left` | `int`: The X coordinate of the left side of the rectangle <br /> |
| `top` | `int`: The Y coordinate of the top of the rectangle <br /> |
| `right` | `int`: The X coordinate of the right side of the rectangle <br /> |
| `bottom` | `int`: The Y coordinate of the bottom of the rectangle <br /> |

## Public methods

### centerX

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int centerX ()
```

<br />

<br />

| Returns ||
|---|---|
| `int` | the horizontal center of the rectangle. If the computed value is fractional, this method returns the largest integer that is less than the computed value. <br /> |

### centerY

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int centerY ()
```

<br />

<br />

| Returns ||
|---|---|
| `int` | the vertical center of the rectangle. If the computed value is fractional, this method returns the largest integer that is less than the computed value. <br /> |

### contains

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean contains (int left, 
                int top, 
                int right, 
                int bottom)
```

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. An empty rectangle never contains another rectangle.

<br />

| Parameters ||
|---|---|
| `left` | `int`: The left side of the rectangle being tested for containment <br /> |
| `top` | `int`: The top of the rectangle being tested for containment <br /> |
| `right` | `int`: The right side of the rectangle being tested for containment <br /> |
| `bottom` | `int`: The bottom of the rectangle being tested for containment <br /> |

| Returns ||
|---|---|
| `boolean` | true iff the 4 specified sides of a rectangle are inside or equal to this rectangle <br /> |

### contains

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean contains (Rect r)
```

Returns true iff the specified rectangle r is inside or equal to this rectangle. An empty rectangle never contains another rectangle.

<br />

| Parameters ||
|---|---|
| `r` | `Rect`: The rectangle being tested for containment. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | true iff the specified rectangle r is inside or equal to this rectangle <br /> |

### contains

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean contains (int x, 
                int y)
```

Returns true if (x,y) is inside the rectangle. The left and top are considered to be inside, while the right and bottom are not. This means that for a x,y to be contained: left \<= x \< right and top \<= y \< bottom. An empty rectangle never contains any point.

<br />

| Parameters ||
|---|---|
| `x` | `int`: The X coordinate of the point being tested for containment <br /> |
| `y` | `int`: The Y coordinate of the point being tested for containment <br /> |

| Returns ||
|---|---|
| `boolean` | true iff (x,y) are contained by the rectangle, where containment means left \<= x \< right and top \<= y \< bottom <br /> |

### describeContents

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int describeContents ()
```

Parcelable interface methods

<br />

| Returns ||
|---|---|
| `int` | a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either `0` or - `https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR` |

### equals

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean equals (Object o)
```

Indicates whether some other object is "equal to" this one.

The `equals` method implements an equivalence relation on non-null object references:

- It is *reflexive*: for any non-null reference value `x`, `x.equals(x)` should return `true`.
- It is *symmetric*: for any non-null reference values `x` and `y`, `x.equals(y)` should return `true` if and only if `y.equals(x)` returns `true`.
- It is *transitive*: for any non-null reference values `x`, `y`, and `z`, if `x.equals(y)` returns `true` and `y.equals(z)` returns `true`, then `x.equals(z)` should return `true`.
- It is *consistent*: for any non-null reference values `x` and `y`, multiple invocations of `x.equals(y)` consistently return `true` or consistently return `false`, provided no information used in `equals` comparisons on the objects is modified.
- For any non-null reference value `x`, `x.equals(null)` should return `false`.

An equivalence relation partitions the elements it operates on into *equivalence classes*; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

<br />

| Parameters ||
|---|---|
| `o` | `Object`: the reference object with which to compare. <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if this object is the same as the obj argument; `false` otherwise. <br /> |

### exactCenterX

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public float exactCenterX ()
```

<br />

<br />

| Returns ||
|---|---|
| `float` | the exact horizontal center of the rectangle as a float. <br /> |

### exactCenterY

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public float exactCenterY ()
```

<br />

<br />

| Returns ||
|---|---|
| `float` | the exact vertical center of the rectangle as a float. <br /> |

### flattenToString

Added in [API level 7](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String flattenToString ()
```

Return a string representation of the rectangle in a well-defined format.

You can later recover the Rect from this string through `https://developer.android.com/reference/android/graphics/Rect#unflattenFromString(java.lang.String)`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | Returns a new String of the form "left top right bottom". This value cannot be `null`. <br /> |

### hashCode

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int hashCode ()
```

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by `https://developer.android.com/reference/java/util/HashMap`.

The general contract of `hashCode` is:

- Whenever it is invoked on the same object more than once during an execution of a Java application, the `hashCode` method must consistently return the same integer, provided no information used in `equals` comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
- If two objects are equal according to the `https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)` method, then calling the `hashCode` method on each of the two objects must produce the same integer result.
- It is *not* required that if two objects are unequal according to the `https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)` method, then calling the `hashCode` method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.

<br />

<br />

| Returns ||
|---|---|
| `int` | a hash code value for this object. <br /> |

### height

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int height ()
```

<br />

<br />

| Returns ||
|---|---|
| `int` | the rectangle's height. This does not check for a valid rectangle (i.e. top \<= bottom) so the result may be negative. <br /> |

### inset

Added in [API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void inset (int left, 
                int top, 
                int right, 
                int bottom)
```

Insets the rectangle on all sides specified by the insets.

<br />

| Parameters ||
|---|---|
| `left` | `int`: The amount to add from the rectangle's left <br /> |
| `top` | `int`: The amount to add from the rectangle's top <br /> |
| `right` | `int`: The amount to subtract from the rectangle's right <br /> |
| `bottom` | `int`: The amount to subtract from the rectangle's bottom <br /> |

### inset

Added in [API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void inset (Insets insets)
```

Insets the rectangle on all sides specified by the dimensions of `insets`.

<br />

| Parameters ||
|---|---|
| `insets` | `Insets`: The insets to inset the rect by. This value cannot be `null`. <br /> |

### inset

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void inset (int dx, 
                int dy)
```

Inset the rectangle by (dx,dy). If dx is positive, then the sides are moved inwards, making the rectangle narrower. If dx is negative, then the sides are moved outwards, making the rectangle wider. The same holds true for dy and the top and bottom.

<br />

| Parameters ||
|---|---|
| `dx` | `int`: The amount to add(subtract) from the rectangle's left(right) <br /> |
| `dy` | `int`: The amount to add(subtract) from the rectangle's top(bottom) <br /> |

### intersect

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean intersect (int left, 
                int top, 
                int right, 
                int bottom)
```

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. No check is performed to see if either rectangle is empty. Note: To just test for intersection, use `https://developer.android.com/reference/android/graphics/Rect#intersects(android.graphics.Rect,%20android.graphics.Rect)`.

<br />

| Parameters ||
|---|---|
| `left` | `int`: The left side of the rectangle being intersected with this rectangle <br /> |
| `top` | `int`: The top of the rectangle being intersected with this rectangle <br /> |
| `right` | `int`: The right side of the rectangle being intersected with this rectangle. <br /> |
| `bottom` | `int`: The bottom of the rectangle being intersected with this rectangle. <br /> |

| Returns ||
|---|---|
| `boolean` | true if the specified rectangle and this rectangle intersect (and this rectangle is then set to that intersection) else return false and do not change this rectangle. <br /> |

### intersect

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean intersect (Rect r)
```

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. No check is performed to see if either rectangle is empty. To just test for intersection, use intersects()

<br />

| Parameters ||
|---|---|
| `r` | `Rect`: The rectangle being intersected with this rectangle. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | true if the specified rectangle and this rectangle intersect (and this rectangle is then set to that intersection) else return false and do not change this rectangle. <br /> |

### intersects

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean intersects (int left, 
                int top, 
                int right, 
                int bottom)
```

Returns true if this rectangle intersects the specified rectangle. In no event is this rectangle modified. No check is performed to see if either rectangle is empty. To record the intersection, use intersect() or setIntersect().

<br />

| Parameters ||
|---|---|
| `left` | `int`: The left side of the rectangle being tested for intersection <br /> |
| `top` | `int`: The top of the rectangle being tested for intersection <br /> |
| `right` | `int`: The right side of the rectangle being tested for intersection <br /> |
| `bottom` | `int`: The bottom of the rectangle being tested for intersection <br /> |

| Returns ||
|---|---|
| `boolean` | true iff the specified rectangle intersects this rectangle. In no event is this rectangle modified. <br /> |

### intersects

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static boolean intersects (Rect a, 
                Rect b)
```

Returns true iff the two specified rectangles intersect. In no event are either of the rectangles modified. To record the intersection, use `https://developer.android.com/reference/android/graphics/Rect#intersect(android.graphics.Rect)` or `https://developer.android.com/reference/android/graphics/Rect#setIntersect(android.graphics.Rect,%20android.graphics.Rect)`.

<br />

| Parameters ||
|---|---|
| `a` | `Rect`: The first rectangle being tested for intersection. This value cannot be `null`. <br /> |
| `b` | `Rect`: The second rectangle being tested for intersection. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | true iff the two specified rectangles intersect. In no event are either of the rectangles modified. <br /> |

### isEmpty

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isEmpty ()
```

Returns true if the rectangle is empty (left \>= right or top \>= bottom)

<br />

| Returns ||
|---|---|
| `boolean` | <br /> |

### offset

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void offset (int dx, 
                int dy)
```

Offset the rectangle by adding dx to its left and right coordinates, and adding dy to its top and bottom coordinates.

<br />

| Parameters ||
|---|---|
| `dx` | `int`: The amount to add to the rectangle's left and right coordinates <br /> |
| `dy` | `int`: The amount to add to the rectangle's top and bottom coordinates <br /> |

### offsetTo

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void offsetTo (int newLeft, 
                int newTop)
```

Offset the rectangle to a specific (left, top) position, keeping its width and height the same.

<br />

| Parameters ||
|---|---|
| `newLeft` | `int`: The new "left" coordinate for the rectangle <br /> |
| `newTop` | `int`: The new "top" coordinate for the rectangle <br /> |

### readFromParcel

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void readFromParcel (Parcel in)
```

Set the rectangle's coordinates from the data stored in the specified parcel. To write a rectangle to a parcel, call writeToParcel().

<br />

| Parameters ||
|---|---|
| `in` | `Parcel`: The parcel to read the rectangle's coordinates from. This value cannot be `null`. <br /> |

### set

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void set (int left, 
                int top, 
                int right, 
                int bottom)
```

Set the rectangle's coordinates to the specified values. Note: no range checking is performed, so it is up to the caller to ensure that left \<= right and top \<= bottom.

<br />

| Parameters ||
|---|---|
| `left` | `int`: The X coordinate of the left side of the rectangle <br /> |
| `top` | `int`: The Y coordinate of the top of the rectangle <br /> |
| `right` | `int`: The X coordinate of the right side of the rectangle <br /> |
| `bottom` | `int`: The Y coordinate of the bottom of the rectangle <br /> |

### set

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void set (Rect src)
```

Copy the coordinates from src into this rectangle.

<br />

| Parameters ||
|---|---|
| `src` | `Rect`: The rectangle whose coordinates are copied into this rectangle. This value cannot be `null`. <br /> |

### setEmpty

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setEmpty ()
```

Set the rectangle to (0,0,0,0)

<br />

### setIntersect

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean setIntersect (Rect a, 
                Rect b)
```

If rectangles a and b intersect, return true and set this rectangle to that intersection, otherwise return false and do not change this rectangle. No check is performed to see if either rectangle is empty. To just test for intersection, use intersects()

<br />

| Parameters ||
|---|---|
| `a` | `Rect`: The first rectangle being intersected with. This value cannot be `null`. <br /> |
| `b` | `Rect`: The second rectangle being intersected with. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | true iff the two specified rectangles intersect. If they do, set this rectangle to that intersection. If they do not, return false and do not change this rectangle. <br /> |

### sort

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void sort ()
```

Swap top/bottom or left/right if there are flipped (i.e. left \> right and/or top \> bottom). This can be called if the edges are computed separately, and may have crossed over each other. If the edges are already correct (i.e. left \<= right and top \<= bottom) then nothing is done.

<br />

### toShortString

Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String toShortString ()
```

Return a string representation of the rectangle in a compact form.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | This value cannot be `null`. <br /> |

### toString

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String toString ()
```

Returns a string representation of the object.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | a string representation of the object. <br /> |

### unflattenFromString

Added in [API level 7](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static Rect unflattenFromString (String str)
```

Returns a Rect from a string of the form returned by `https://developer.android.com/reference/android/graphics/Rect#flattenToString()`, or null if the string is not of that form.

<br />

| Parameters ||
|---|---|
| `str` | `String`: This value may be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Rect` | <br /> |

### union

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void union (int left, 
                int top, 
                int right, 
                int bottom)
```

Update this Rect to enclose itself and the specified rectangle. If the specified rectangle is empty, nothing is done. If this rectangle is empty it is set to the specified rectangle.

<br />

| Parameters ||
|---|---|
| `left` | `int`: The left edge being unioned with this rectangle <br /> |
| `top` | `int`: The top edge being unioned with this rectangle <br /> |
| `right` | `int`: The right edge being unioned with this rectangle <br /> |
| `bottom` | `int`: The bottom edge being unioned with this rectangle <br /> |

### union

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void union (Rect r)
```

Update this Rect to enclose itself and the specified rectangle. If the specified rectangle is empty, nothing is done. If this rectangle is empty it is set to the specified rectangle.

<br />

| Parameters ||
|---|---|
| `r` | `Rect`: The rectangle being unioned with this rectangle. This value cannot be `null`. <br /> |

### union

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void union (int x, 
                int y)
```

Update this Rect to enclose itself and the \[x,y\] coordinate. There is no check to see that this rectangle is non-empty.

<br />

| Parameters ||
|---|---|
| `x` | `int`: The x coordinate of the point to add to the rectangle <br /> |
| `y` | `int`: The y coordinate of the point to add to the rectangle <br /> |

### width

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int width ()
```

<br />

<br />

| Returns ||
|---|---|
| `int` | the rectangle's width. This does not check for a valid rectangle (i.e. left \<= right) so the result may be negative. <br /> |

### writeToParcel

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void writeToParcel (Parcel out, 
                int flags)
```

Write this rectangle to the specified parcel. To restore a rectangle from a parcel, use readFromParcel()

<br />

| Parameters ||
|---|---|
| `out` | `Parcel`: The parcel to write the rectangle's coordinates into <br /> |
| `flags` | `int`: Additional flags about how the object should be written. May be 0 or `https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE`. Value is either `0` or a combination of the following: - `https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE` |