Reference:Android.graphics.Rect
From Triled Wiki
android.graphics
public final class android.graphics.Rect
| java.lang.Object | ||
| android.graphics.Rect | Parcelable | |
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).
[edit] Summary
[edit] Constants
| Value | ||||
|---|---|---|---|---|
| Creator | CREATOR |
[edit] Fields
| public | int | bottom | |||
| public | int | left | |||
| public | int | right | |||
| public | int | top |
[edit] 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). | |||||
[edit] Public Methods
| boolean | contains (int x, int y) | ||||
| Returns true if (x,y) is inside the rectangle. | |||||
| boolean | contains (Rect r) | ||||
| Returns true iff the specified rectangle r is inside or equal to this rectangle. | |||||
| 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 | equals (Object obj) | ||||
| Compares the argument to the receiver, and answers true if they represent the same object using a class specific comparison. | |||||
| int | height () | ||||
| 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. | |||||
| final | 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 (Rect src) | ||||
| Copy the coordinates from src into this rectangle. | |||||
| void | set (int left, int top, int right, int bottom) | ||||
| Set the rectangle's coordinates to the specified values. | |||||
| 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 | toString () | ||||
| Answers a string containing a concise, human-readable description of the receiver. | |||||
| 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. | |||||
| final | int | width () | |||
| void | writeToParcel (Parcel out) | ||||
| Write this rectangle to the specified parcel. | |||||
[edit] Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait[edit] Methods inherited from interface android.os.Parcelable
[edit] Details
[edit] Constants
[edit] public static final Creator CREATOR
[edit] Fields
[edit] public int bottom
[edit] public int left
[edit] public int right
[edit] public int top
[edit] Public Constructors
[edit] public Rect()
Create a new empty Rect. All coordinates are initialized to 0.
[edit] 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 | The X coordinate of the left side of the rectagle |
|---|---|
| top | The Y coordinate of the top of the rectangle |
| right | The X coordinate of the right side of the rectagle |
| bottom | The Y coordinate of the bottom of the rectangle |
[edit] public Rect(Rect r)
Create a new rectangle, initialized with the values in the specified rectangle (which is left unmodified).
Parameters
| r | The rectangle whose coordinates are copied into the new rectangle. |
|---|
[edit] Public Methods
[edit] 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 | The X coordinate of the point being tested for containment |
|---|---|
| y | The Y coordinate of the point being tested for containment |
Returns
- true iff (x,y) are contained by the rectangle, where containment means left <= x < right and top <= y < bottom
[edit] 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 | The rectangle being tested for containment. |
|---|
Returns
- true iff the specified rectangle r is inside or equal to this rectangle
[edit] 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 | The left side of the rectangle being tested for containment |
|---|---|
| top | The top of the rectangle being tested for containment |
| right | The right side of the rectangle being tested for containment |
| bottom | The bottom of the rectangle being tested for containment |
Returns
- true iff the the 4 specified sides of a rectangle are inside or equal to this rectangle
[edit] public boolean equals(Object obj)
Compares the argument to the receiver, and answers true if they represent the same object using a class specific comparison. The implementation in Object answers true only if the argument is the exact same object as the receiver (==).
Parameters
| obj | Object the object to compare with this object. |
|---|
[edit] public int height()
Returns
- the rectangle's height. This does not check for a valid rectangle (i.e. top <= bottom) so the result may be negative.
[edit] 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 | The amount to add(subtract) from the rectangle's left(right) |
|---|---|
| dy | The amount to add(subtract) from the rectangle's top(bottom) |
[edit] 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()
Parameters
| left | The left side of the rectangle being intersected with this rectangle |
|---|---|
| top | The top of the rectangle being intersected with this rectangle |
| right | The right side of the rectangle being intersected with this rectangle. |
| bottom | The bottom of the rectangle being intersected with this rectangle. |
Returns
- 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.
[edit] 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 | The rectangle being intersected with this rectangle. |
|---|
Returns
- 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.
[edit] 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 | The left side of the rectangle being tested for intersection |
|---|---|
| top | The top of the rectangle being tested for intersection |
| right | The right side of the rectangle being tested for intersection |
| bottom | The bottom of the rectangle being tested for intersection |
Returns
- true iff the specified rectangle intersects this rectangle. In no event is this rectangle modified.
[edit] 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() or setIntersect().
Parameters
| a | The first rectangle being tested for intersection |
|---|---|
| b | The second rectangle being tested for intersection |
Returns
- true iff the two specified rectangles intersect. In no event are either of the rectangles modified.
[edit] public final boolean isEmpty()
Returns true if the rectangle is empty (left >= right or top >= bottom)
[edit] 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 | The amount to add to the rectangle's left and right coordinates |
|---|---|
| dy | The amount to add to the rectangle's top and bottom coordinates |
[edit] 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 | The new "left" coordinate for the rectangle |
|---|---|
| newTop | The new "top" coordinate for the rectangle |
[edit] 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 | The parcel to read the rectangle's coordinates from |
|---|
[edit] public void set(Rect src)
Copy the coordinates from src into this rectangle.
Parameters
| src | The rectangle whose coordinates are copied into this rectangle. |
|---|
[edit] 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 | The X coordinate of the left side of the rectagle |
|---|---|
| top | The Y coordinate of the top of the rectangle |
| right | The X coordinate of the right side of the rectagle |
| bottom | The Y coordinate of the bottom of the rectangle |
[edit] public void setEmpty()
Set the rectangle to (0,0,0,0)
[edit] 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 | The first rectangle being intersected with |
|---|---|
| b | The second rectangle being intersected with |
Returns
- 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.
[edit] 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.
[edit] public String toString()
Answers a string containing a concise, human-readable description of the receiver.
[edit] 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 | The left edge being unioned with this rectangle |
|---|---|
| top | The top edge being unioned with this rectangle |
| right | The right edge being unioned with this rectangle |
| bottom | The bottom edge being unioned with this rectangle |
[edit] 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 | The rectangle being unioned with this rectangle |
|---|
[edit] public final int width()
Returns
- the rectangle's width. This does not check for a valid rectangle (i.e. left <= right) so the result may be negative.
[edit] public void writeToParcel(Parcel out)
Write this rectangle to the specified parcel. To restore a rectangle from a parcel, use readFromParcel()
Parameters
| out | The parcel to write the rectangle's coordinates into |
|---|
[edit] References
- Original documentation page for Android SDK build m5-rc15e - 14 apr 2008 17:27
