Sequenceablepublic class Rect extends Object implements Sequenceable
This class is used to specify the rectangle area on the screen after you draw or outline a rectangle.
| 限定符和类型 | 类 | 说明 |
|---|---|---|
static class |
Rect.RotationEnum |
Indicates the rotation angle.
|
Sequenceable.Producer<T>| 限定符和类型 | 字段 | 说明 |
|---|---|---|
int |
bottom |
Indicates the position of the Y coordinate on the bottom of the rectangle.
|
int |
left |
Indicates the position of the X coordinate on the left of the rectangle.
|
int |
right |
Indicates the position of the X coordinate on the right of the rectangle.
|
int |
top |
Indicates the position of the Y coordinate on the top of the rectangle.
|
| 构造器 | 说明 |
|---|---|
Rect() |
Default constructor used to create a
Rect instance. |
Rect(int left,
int top,
int right,
int bottom) |
A constructor used to create a
Rect instance. |
Rect(Rect rect) |
A constructor used to create a
Rect instance by using a rectangle with integer coordinates. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
void |
clear() |
Clears this
Rect. |
boolean |
contains(int left,
int top,
int right,
int bottom) |
Checks whether a specified rectangle is inside or equals to this rectangle.
|
String |
convertRectToValue() |
Converts the current rectangle into a string in the specified pattern "left top right bottom".
|
static Rect |
convertValueToRect(String str) |
Converts a string of the specified pattern into a rectangle.
|
boolean |
equals(Object object) |
Indicates whether some other object is "equal to" this one.
|
void |
fetchParcel(Parcel parcel) |
Set the rectangle params according to data stored in the parcel.
|
void |
fuse(int xCoor,
int yCoor) |
Combines this rectangle and the specified point.
|
void |
fuse(int left,
int top,
int right,
int bottom) |
Fuses this
Rect with a specified rectangle holding given coordinates. |
void |
fuse(Rect rect) |
Fuses this
Rect with a specified rectangle. |
int[] |
getCenter() |
Obtains an array of coordinates of the center point of this
Rect object. |
int |
getCenterX() |
Obtains the X-axis center of a rectangle.
|
int |
getCenterY() |
Obtains the Y-axis center of a rectangle.
|
int |
getHeight() |
Obtains the height of a rectangle.
|
boolean |
getIntersectRect(int left,
int top,
int right,
int bottom) |
Checks whether this
Rect intersects a specified rectangle with given coordinates and sets this
Rect to that intersection if they intersect. |
boolean |
getIntersectRect(Rect rect) |
Checks whether this
Rect intersects a specified rectangle and sets this Rect to that intersection
if they intersect. |
boolean |
getIntersectRect(Rect rectA,
Rect rectB) |
Checks whether two specified rectangles intersect, and sets this rectangle to that intersection (if any).
|
Point |
getPivot() |
Obtains the coordinates of the pivot, around which this
Rect object is rotated and scaled. |
int |
getPivotXCoordinate() |
Obtains the X-axis coordinate of the pivot, around which this
Rect object is rotated and scaled. |
int |
getPivotYCoordinate() |
Obtains the Y-axis coordinate of the pivot, around which this
Rect object is rotated and scaled. |
Point |
getPreciseCenter() |
Obtains the coordinates of the center point of this
Rect object. |
float |
getPreciseHorizontalCenter() |
Obtains the coordinates of the precise horizontal center of this
Rect. |
float |
getPreciseVerticalCenter() |
Obtains the coordinates of the precise vertical center of this
Rect. |
int[] |
getRectSize() |
Obtains the size of this
Rect object. |
int |
getWidth() |
Obtains the width of a rectangle.
|
int |
hashCode() |
Returns a hash code value for the object.
|
boolean |
isEmpty() |
Checks whether a rectangle is empty.
|
boolean |
isInclude(int x,
int y) |
Checks whether a specified point is inside this
Rect. |
boolean |
isInclude(int left,
int top,
int right,
int bottom) |
Checks whether the rectangle specified by
left, top, right
and bottom is inside this Rect object. |
boolean |
isInclude(Point point) |
Checks whether the coordinates of a specified point are inside this
Rect object. |
boolean |
isInclude(Rect rect) |
Checks whether a specified rectangle is inside this
Rect. |
boolean |
isIntersect(int left,
int top,
int right,
int bottom) |
Checks whether this
Rect intersects a specified rectangle. |
boolean |
isIntersect(Rect rect) |
Checks whether the specified rectangle intersects with this
Rect object. |
static boolean |
isIntersect(Rect rectA,
Rect rectB) |
Checks whether two specified rectangles intersect.
|
boolean |
marshalling(Parcel out) |
Marshals this
Sequenceable object into a Parcel. |
void |
modify(Rect rect) |
Modifies the position of this
Rect based on the position of a specified rectangle. |
Rect |
obtainIntersectRect(int left,
int top,
int right,
int bottom) |
Obtains the intersection rectangle of this
Rect object and the rectangle determined by left,
top, right, and bottom. |
Rect |
obtainIntersectRect(Rect rect) |
Obtains the intersection rectangle of the specified rectangle and this
Rect object. |
void |
offset(int dx,
int dy) |
Offsets this rectangle by a specified distance.
|
void |
recordParcel(Parcel parcel) |
Put the param of rectangle into the parcel.
|
void |
reorder() |
Swaps the top and bottom bounds and/or left and right bounds, if the rectangle is invalid.
|
void |
rotateBy(Rect.RotationEnum rotationEnum) |
Rotates this
Rect object by a specified number of degrees. |
void |
scale(float scale) |
Sets the scale ratio for this
Rect object. |
void |
set(int left,
int top,
int right,
int bottom) |
Sets the shape and size of the rectangle based on the positions of its four sides.
|
void |
setPivot(int x,
int y) |
Sets the pivot, around which this
Rect object is rotated and scaled based on x and y. |
void |
setPivot(Point point) |
Sets the pivot, around which this
Rect object is rotated and scaled based on point. |
void |
setPivotXCoordinate(int x) |
Sets the X-axis coordinate of the pivot, around which this
Rect object is rotated and scaled. |
void |
setPivotYCoordinate(int y) |
Sets the Y-axis coordinate of the pivot, around which this
Rect object is rotated and scaled. |
void |
shrink(int dx,
int dy) |
Shrinks this
Rect. |
void |
sort() |
Swaps the x-coordinates of upper left and lower right corners and/or y-coordinates of upper left and lower
right corners, if this rectangle is invalid.
|
String |
toString() |
Returns a string representation of the object.
|
void |
translate(int dx,
int dy) |
Translates this
Rect. |
void |
translateCenterTo(int centerX,
int centerY) |
Translates the center point of this
Rect object to a new position determined
by centerX and centerY. |
void |
translateCenterTo(Point point) |
Translates the center point of this
Rect object to a new position identified by point. |
void |
translateTo(int newLeft,
int newTop) |
Translates this
Rect to a new position. |
boolean |
unmarshalling(Parcel in) |
Unmarshals this
Sequenceable object from a Parcel. |
boolean |
verifyRect() |
Checks whether this
Rect object is valid. |
hasFileDescriptorpublic int bottom
This variable defines the Y coordinate on the vertical axis where the bottom side of the rectangle locates on the screen.
public int left
This variable defines the X coordinate on the horizontal axis where the left side of the rectangle locates on the screen.
public int right
This variable defines the X coordinate on the horizontal axis where the right side of the rectangle locates on the screen.
public int top
This variable defines the Y coordinate on the vertical axis where the top side of the rectangle locates on the screen.
public Rect()
Rect instance.
This method is used to define a rectangle object, which is the point in the upper left corner of the screen by default.
public Rect(int left,
int top,
int right,
int bottom)
Rect instance.
This method is used to define a rectangle object based on the positions of the four sides in the coordinate space.
left - Indicates the position of the X coordinate on the left of the rectangle object.top - Indicates the position of the Y coordinate on the top of the rectangle object.right - Indicates the position of the X coordinate on the right of the rectangle object.bottom - Indicates the position of the Y coordinate on the bottom of the rectangle object.public void set(int left,
int top,
int right,
int bottom)
left - Indicates the position of the X coordinate on the left of the rectangle object.top - Indicates the position of the Y coordinate on the top of the rectangle object.right - Indicates the position of the X coordinate on the right of the rectangle object.bottom - Indicates the position of the Y coordinate on the bottom of the rectangle object.public final boolean isEmpty()
true if the rectangle is empty; returns false otherwise.public final boolean verifyRect()
Rect object is valid.true if the X-axis and Y-axis coordinates of the rectangle's upper left corner
are less than those of the rectangle's lower right corner; returns false otherwise.public final int getWidth()
If the right value of the rectangle is smaller than the left value, a negative value will be returned.
public final int getHeight()
If the bottom value of the rectangle is smaller than the top value, a negative value will be returned.
public final int getCenterX()
The X-axis center of a rectangle is represented by a rounded down integer.
public final int getCenterY()
The Y-axis center of a rectangle is represented by a rounded down integer.
public int[] getCenter()
Rect object.Rect object.
The first value represents the value in the X axis, and the second one represents the value in the Y axis.public int[] getRectSize()
Rect object.public boolean equals(Object object)
The equals method implements an equivalence relation
on non-null object references:
x, x.equals(x) should return
true.
x and y, x.equals(y)
should return true if and only if
y.equals(x) returns true.
x, y, and z, if
x.equals(y) returns true and
y.equals(z) returns true, then
x.equals(z) should return true.
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.
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.
equals 在类中 Objectobject - the reference object with which to compare.true if this object is the same as the obj
argument; false otherwise.Object.hashCode(),
HashMappublic int hashCode()
HashMap.
The general contract of hashCode is:
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.
equals(Object)
method, then calling the hashCode method on each of
the two objects must produce the same integer result.
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.
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.)
hashCode 在类中 ObjectObject.equals(java.lang.Object),
System.identityHashCode(java.lang.Object)public String toString()
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())
public boolean marshalling(Parcel out)
SequenceableSequenceable object into a Parcel.marshalling 在接口中 Sequenceableout - Indicates the Parcel object to which the Sequenceable
object will be marshaled..true if the marshalling is successful; returns false otherwise.public boolean unmarshalling(Parcel in)
SequenceableSequenceable object from a Parcel.unmarshalling 在接口中 Sequenceablein - Indicates the Parcel object into which the Sequenceable
object has been marshaled.true if the unmarshalling is successful; returns false otherwise.public boolean isInclude(int x,
int y)
Rect.x - Indicates the X coordinate of the specified point.y - Indicates the Y coordinate of the specified point.true if the specified point is inside this Rect; returns false otherwise.public boolean isInclude(Point point)
Rect object.true if the coordinates of the specified point are inside this Rect object;
returns false otherwise.public boolean isInclude(Rect rect)
Rect.rect - Indicates the specified rectangle.true if the specified rectangle is inside this Rect; returns false
otherwise.public boolean isInclude(int left,
int top,
int right,
int bottom)
left, top, right
and bottom is inside this Rect object.left - Indicates the left boundary of the specified rectangle.top - Indicates the top boundary of the specified rectangle.right - Indicates the right boundary of the specified rectangle.bottom - Indicates the bottom boundary of the specified rectangle.true if the specified rectangle is inside this Rect object;
returns false otherwise.public final float getPreciseHorizontalCenter()
Rect.public final float getPreciseVerticalCenter()
Rect.public Point getPreciseCenter()
Rect object.Point object representing the coordinates of the center point of this Rect object.public void setPivot(int x,
int y)
Rect object is rotated and scaled based on x and y.x - Indicates the X-axis coordinate of the pivot to set.y - Indicates the Y-axis coordinate of the pivot to set.setPivotXCoordinate(int),
getPivotXCoordinate(),
setPivotYCoordinate(int),
getPivotYCoordinate(),
getPivot(),
setPivot(Point)public void setPivot(Point point)
Rect object is rotated and scaled based on point.point - Indicates the coordinates of the pivot to set.setPivotXCoordinate(int),
getPivotXCoordinate(),
setPivotYCoordinate(int),
getPivotYCoordinate(),
getPivot(),
setPivot(Point)public void setPivotXCoordinate(int x)
Rect object is rotated and scaled.x - Indicates the X-axis coordinate of the pivot to set.setPivotXCoordinate(int),
getPivotXCoordinate(),
setPivotYCoordinate(int),
getPivotYCoordinate(),
getPivot(),
setPivot(Point)public void setPivotYCoordinate(int y)
Rect object is rotated and scaled.y - Indicates the Y-axis coordinate of the pivot to set.setPivotXCoordinate(int),
getPivotXCoordinate(),
setPivotYCoordinate(int),
getPivotYCoordinate(),
getPivot(),
setPivot(Point)public Point getPivot()
Rect object is rotated and scaled.setPivotXCoordinate(int),
getPivotXCoordinate(),
setPivotYCoordinate(int),
getPivotYCoordinate(),
getPivot(),
setPivot(Point)public int getPivotXCoordinate()
Rect object is rotated and scaled.setPivotXCoordinate(int),
getPivotXCoordinate(),
setPivotYCoordinate(int),
getPivotYCoordinate(),
getPivot(),
setPivot(Point)public int getPivotYCoordinate()
Rect object is rotated and scaled.setPivotXCoordinate(int),
getPivotXCoordinate(),
setPivotYCoordinate(int),
getPivotYCoordinate(),
getPivot(),
setPivot(Point)public void fetchParcel(Parcel parcel)
parcel - Indicates the parcel.public void recordParcel(Parcel parcel)
parcel - Indicates the parcel.public void scale(float scale)
Rect object.scale - Indicates the scale ratio to set.public void rotateBy(Rect.RotationEnum rotationEnum)
Rect object by a specified number of degrees.rotationEnum - Indicates the number of degrees by which this Rect object will be rotated.
For details about available values, see RotationEnum.public void shrink(int dx,
int dy)
Rect.dx - Indicates the horizontal length to shrink, in pixels.dy - Indicates the vertical length to shrink, in pixels.public static boolean isIntersect(Rect rectA, Rect rectB)
rectA - Indicates one rectangle to check.rectB - Indicates the other rectangle to check.true if the two specified rectangles intersect; returns false otherwise.public void translate(int dx,
int dy)
Rect.dx - Indicates the horizontal length to translate, in pixels.dy - Indicates the vertical length to translate, in pixels.public void translateTo(int newLeft,
int newTop)
Rect to a new position.newLeft - Indicates the X coordinate of the upper left corner of the rectangle at the new position.newTop - Indicates the Y coordinate of the upper left corner of the rectangle at the new position.public void translateCenterTo(int centerX,
int centerY)
Rect object to a new position determined
by centerX and centerY.centerX - Indicates the X-axis coordinate of the rectangle's new center point.centerY - Indicates the Y-axis coordinate of the rectangle's new center point.public void translateCenterTo(Point point)
Rect object to a new position identified by point.point - Indicates the coordinates of the rectangle's new center point.public void modify(Rect rect)
Rect based on the position of a specified rectangle.rect - Indicates the specified rectangle.public void clear()
Rect.public void fuse(int left,
int top,
int right,
int bottom)
Rect with a specified rectangle holding given coordinates.left - Indicates the X coordinate of the upper left corner of the specified rectangle.top - Indicates the Y coordinate of the upper left corner of the specified rectangle.right - Indicates the X coordinate of the lower right corner of the specified rectangle.bottom - Indicates the Y coordinate of the lower right corner of the specified rectangle.public void fuse(Rect rect)
Rect with a specified rectangle.rect - Indicates the specified rectangle.public void fuse(int xCoor,
int yCoor)
xCoor - Indicates the X coordinate of the specified point.yCoor - Indicates the Y coordinate of the specified point.public boolean getIntersectRect(int left,
int top,
int right,
int bottom)
Rect intersects a specified rectangle with given coordinates and sets this
Rect to that intersection if they intersect.left - Indicates the X coordinate of the upper left corner of the specified rectangle.top - Indicates the Y coordinate of the upper left corner of the specified rectangle.right - Indicates the X coordinate of the lower right corner of the specified rectangle.bottom - Indicates the Y coordinate of the lower right corner of the specified rectangle.true if this Rect intersects the specified rectangle; returns false
otherwise.public boolean getIntersectRect(Rect rect)
Rect intersects a specified rectangle and sets this Rect to that intersection
if they intersect.rect - Indicates the specified rectangle.true if this Rect intersects the specified rectangle; returns false
otherwise.public boolean isIntersect(int left,
int top,
int right,
int bottom)
Rect intersects a specified rectangle.left - Indicates the X coordinate of the upper left corner of the specified rectangle.top - Indicates the Y coordinate of the upper left corner of the specified rectangle.right - Indicates the X coordinate of the lower right corner of the specified rectangle.bottom - Indicates the Y coordinate of the lower right corner of the specified rectangle.true if this Rect intersects the specified rectangle; returns false
otherwise.obtainIntersectRect(int, int, int, int)public boolean isIntersect(Rect rect)
Rect object.rect - Indicates the rectangle to check.true if this Rect object intersects with the specified rectangle;
returns false otherwise.public Rect obtainIntersectRect(int left, int top, int right, int bottom)
Rect object and the rectangle determined by left,
top, right, and bottom.left - Indicates the X-axis coordinate of the upper left corner of the specified rectangle.top - Indicates the Y-axis coordinate of the upper left corner of the specified rectangle.right - Indicates the X-axis coordinate of the lower right corner of the specified rectangle.bottom - Indicates the Y-axis coordinate of the lower right corner of the specified rectangle.Rect object.public Rect obtainIntersectRect(Rect rect)
Rect object.rect - Indicates the specified rectangle.Rect object.public void reorder()
public boolean getIntersectRect(Rect rectA, Rect rectB)
rectA - Indicates the first rectangle.rectB - Indicates the second rectangle.true if the two specified rectangles intersect; returns false otherwise.public String convertRectToValue()
public static Rect convertValueToRect(String str)
str - Indicates the string in the specified pattern "left top right bottom".public void offset(int dx,
int dy)
dx - Indicates the offset of the rectangle on the x-axis.dy - Indicates the offset of the rectangle on the y-axis.public boolean contains(int left,
int top,
int right,
int bottom)
left - Indicates the x-coordinate of the upper left corner of the specified rectangle.top - Indicates the y-coordinate of the upper left corner of the specified rectangle.right - Indicates the x-coordinate of the lower right corner of the specified rectangle.bottom - Indicates the y-coordinate of the lower right corner of the specified rectangle.true if the specified rectangle is inside or equals to this rectangle;
returns false otherwise.public void sort()