# Print output for @column tags ?>
Developers

- Design
- Develop
- Distribute

Developer Console

## Most visited

## Recently visited

## Results for

Summary: Inherited Constants | Fields | Ctors | Methods | Inherited Methods

# Rect

`public final class Rect`
`extends Object` `implements Parcelable`

java.lang.Object
↳ | android.graphics.Rect

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 `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 `android.os.Parcelable`
`int` | `CONTENTS_FILE_DESCRIPTOR` Descriptor bit used with `describeContents()`: indicates that the Parcelable object's flattened representation includes a file descriptor.
`int` | `PARCELABLE_WRITE_RETURN_VALUE` Flag for use with `writeToParcel(Parcel, int)`: 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 Creator<Rect>` | `CREATOR`
`public int` | `bottom`
`public int` | `left`
`public int` | `right`
`public int` | `top`

### Public constructors
`Rect()` Create a new empty Rect.
`Rect(int left, int top, int right, int bottom)` Create a new rectangle with the specified coordinates.
`Rect(Rect r)` Create a new rectangle, initialized with the values in the specified rectangle (which is left unmodified).

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

### Inherited methods
From class `java.lang.Object`
`Object` | `clone()` Creates and returns a copy of this object.
`boolean` | `equals(Object obj)` Indicates whether some other object is "equal to" this one.
`void` | `finalize()` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
`final Class<?>` | `getClass()` Returns the runtime class of this `Object`.
`int` | `hashCode()` Returns a hash code value for the object.
`final void` | `notify()` Wakes up a single thread that is waiting on this object's monitor.
`final void` | `notifyAll()` Wakes up all threads that are waiting on this object's monitor.
`String` | `toString()` Returns a string representation of the object.
`final void` | `wait(long timeout, int nanos)` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
`final void` | `wait(long timeout)` Causes the current thread to wait until either another thread invokes the `notify()` method or the `notifyAll()` method for this object, or a specified amount of time has elapsed.
`final void` | `wait()` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object.
From interface `android.os.Parcelable`
`abstract int` | `describeContents()` Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.
`abstract void` | `writeToParcel(Parcel dest, int flags)` Flatten this object in to a Parcel.

## Fields

### CREATOR

    public static final Creator<Rect> CREATOR

### bottom

    public int bottom

### left

    public int left

### right

    public int right

### top

    public int top

## Public constructors

### Rect

    public Rect ()

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

### Rect

    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.

Parameters
`left` | `int`: The X coordinate of the left side of the rectangle
`top` | `int`: The Y coordinate of the top of the rectangle
`right` | `int`: The X coordinate of the right side of the rectangle
`bottom` | `int`: The Y coordinate of the bottom of the rectangle

### Rect

    public Rect (Rect r)

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

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

## Public methods

### centerX

    public int centerX ()

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.

### centerY

    public int centerY ()

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.

### contains

    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.

Parameters
`left` | `int`: The left side of the rectangle being tested for containment
`top` | `int`: The top of the rectangle being tested for containment
`right` | `int`: The right side of the rectangle being tested for containment
`bottom` | `int`: The bottom of the rectangle being tested for containment

Returns
`boolean` | true iff the the 4 specified sides of a rectangle are inside or equal to this rectangle

### contains

    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.

Parameters
`r` | `Rect`: The rectangle being tested for containment. This value cannot be `null`.

Returns
`boolean` | true iff the specified rectangle r is inside or equal to this rectangle

### contains

    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.

Parameters
`x` | `int`: The X coordinate of the point being tested for containment
`y` | `int`: The Y coordinate of the point being tested for containment

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

### describeContents

    public int describeContents ()

Parcelable interface methods

Returns
`int` | a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either `0` or `CONTENTS_FILE_DESCRIPTOR`

### equals

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

The `equals` method for class `Object` implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values `x` and `y`, this method returns `true` if and only if `x` and `y` refer to the same object (`x == y` has the value `true`).

Note that it is generally necessary to override the `hashCode` method whenever this method is overridden, so as to maintain the general contract for the `hashCode` method, which states that equal objects must have equal hash codes.

Parameters
`o` | `Object`: the reference object with which to compare.

Returns
`boolean` | `true` if this object is the same as the obj argument; `false` otherwise.

### exactCenterX

    public float exactCenterX ()

Returns
`float` | the exact horizontal center of the rectangle as a float.

### exactCenterY

    public float exactCenterY ()

Returns
`float` | the exact vertical center of the rectangle as a float.

### flattenToString

    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 `unflattenFromString(java.lang.String)`.

Returns
`String` | Returns a new String of the form "left top right bottom" This value cannot be `null`.

### hashCode

    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 `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 `equals(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 `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.

As much as is reasonably practical, the hashCode method defined by class `Object` does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the Java™ programming language.)

Returns
`int` | a hash code value for this object.

### height

    public int height ()

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

### inset

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

Insets the rectangle on all sides specified by the insets.

Parameters
`left` | `int`: The amount to add from the rectangle's left
`top` | `int`: The amount to add from the rectangle's top
`right` | `int`: The amount to subtract from the rectangle's right
`bottom` | `int`: The amount to subtract from the rectangle's bottom

### inset

    public void inset (Insets insets)

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

Parameters
`insets` | `Insets`: The insets to inset the rect by. This value cannot be `null`.

### inset

    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.

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

### intersect

    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 `intersects(android.graphics.Rect, android.graphics.Rect)`.

Parameters
`left` | `int`: The left side of the rectangle being intersected with this rectangle
`top` | `int`: The top of the rectangle being intersected with this rectangle
`right` | `int`: The right side of the rectangle being intersected with this rectangle.
`bottom` | `int`: The bottom of the rectangle being intersected with this rectangle.

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.

### intersect

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

Parameters
`r` | `Rect`: The rectangle being intersected with this rectangle. This value cannot be `null`.

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.

### intersects

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

Parameters
`left` | `int`: The left side of the rectangle being tested for intersection
`top` | `int`: The top of the rectangle being tested for intersection
`right` | `int`: The right side of the rectangle being tested for intersection
`bottom` | `int`: The bottom of the rectangle being tested for intersection

Returns
`boolean` | true iff the specified rectangle intersects this rectangle. In no event is this rectangle modified.

### intersects

    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 `intersect(android.graphics.Rect)` or `setIntersect(android.graphics.Rect, android.graphics.Rect)`.

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

Returns
`boolean` | true iff the two specified rectangles intersect. In no event are either of the rectangles modified.

### isEmpty

    public boolean isEmpty ()

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

Returns
`boolean` |

### offset

    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.

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

### offsetTo

    public void offsetTo (int newLeft,
                    int newTop)

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

Parameters
`newLeft` | `int`: The new "left" coordinate for the rectangle
`newTop` | `int`: The new "top" coordinate for the rectangle

### readFromParcel

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

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

### set

    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.

Parameters
`left` | `int`: The X coordinate of the left side of the rectangle
`top` | `int`: The Y coordinate of the top of the rectangle
`right` | `int`: The X coordinate of the right side of the rectangle
`bottom` | `int`: The Y coordinate of the bottom of the rectangle

### set

    public void set (Rect src)

Copy the coordinates from src into this rectangle.

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

### setEmpty

    public void setEmpty ()

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

### setIntersect

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

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

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.

### sort

    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.

### toShortString

    public String toShortString ()

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

Returns
`String` | This value cannot be `null`.

### toString

    public String toString ()

Returns a string representation of the object. In general, the `toString` method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The `toString` method for class `Object` returns a string consisting of the name of the class of which the object is an instance, the at-sign character ``@`', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

>      getClass().getName() + '@' + Integer.toHexString(hashCode())

Returns
`String` | a string representation of the object.

### unflattenFromString

    public static Rect unflattenFromString (String str)

Returns a Rect from a string of the form returned by `flattenToString()`, or null if the string is not of that form.

Parameters
`str` | `String`: This value may be `null`.

Returns
`Rect` |

### union

    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.

Parameters
`left` | `int`: The left edge being unioned with this rectangle
`top` | `int`: The top edge being unioned with this rectangle
`right` | `int`: The right edge being unioned with this rectangle
`bottom` | `int`: The bottom edge being unioned with this rectangle

### union

    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.

Parameters
`r` | `Rect`: The rectangle being unioned with this rectangle This value cannot be `null`.

### union

    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.

Parameters
`x` | `int`: The x coordinate of the point to add to the rectangle
`y` | `int`: The y coordinate of the point to add to the rectangle

### width

    public int width ()

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

### writeToParcel

    public void writeToParcel (Parcel out,
                    int flags)

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

Parameters
`out` | `Parcel`: The parcel to write the rectangle's coordinates into
`flags` | `int`: Additional flags about how the object should be written. May be 0 or `Parcelable.PARCELABLE_WRITE_RETURN_VALUE`. Value is either `0` or a combination of `Parcelable.PARCELABLE_WRITE_RETURN_VALUE`, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES

Full name *
Email address *
Company / developer name
One of your Play Store app URLs *
Which best describes your business:*
Apps
Games
Apps & Games
*
*