Most visited

Recently visited

Added in API level 1

RectF

public class RectF
extends Object implements Parcelable

java.lang.Object
   ↳ android.graphics.RectF


RectF为矩形保存四个浮点坐标。 该矩形由其4条边的坐标(左,上,右下)表示。 这些字段可以直接访问。 使用width()和height()来检索矩形的宽度和高度。 注意:大多数方法不检查是否正确排列坐标(即,<=右和<=下)。

Summary

Inherited constants

From interface android.os.Parcelable

Fields

public static final Creator<RectF> CREATOR

public float bottom

public float left

public float right

public float top

Public constructors

RectF()

创建一个新的空RectF。

RectF(float left, float top, float right, float bottom)

用指定的坐标创建一个新的矩形。

RectF(RectF r)

创建一个新的矩形,使用指定矩形中的值进行初始化(未作任何修改)。

RectF(Rect r)

Public methods

final float centerX()
final float centerY()
boolean contains(float left, float top, float right, float bottom)

如果矩形的4个指定边在此矩形内或等于此矩形,则返回true。

boolean contains(RectF r)

如果指定的矩形r在此矩形内或等于此矩形,则返回true。

boolean contains(float x, float y)

如果(x,y)在矩形内,则返回true。

int describeContents()

Parcelable接口方法

boolean equals(Object o)

指示其他某个对象是否“等于”这一个。

int hashCode()

返回对象的哈希码值。

final float height()
void inset(float dx, float dy)

(dx,dy)插入矩形。

boolean intersect(RectF r)

如果指定的矩形与此矩形相交,则返回true并将此矩形设置为该交点,否则返回false并不更改此矩形。

boolean intersect(float left, float top, float right, float bottom)

如果由left,top,right,bottom指定的矩形与此矩形相交,则返回true并将此矩形设置为该交点,否则返回false并且不更改此矩形。

boolean intersects(float left, float top, float right, float bottom)

如果此矩形与指定的矩形相交,则返回true。

static boolean intersects(RectF a, RectF b)

如果两个指定的矩形相交,则返回true。

final boolean isEmpty()

如果矩形是空的,则返回true(left> = right或top> = bottom)

void offset(float dx, float dy)

通过将dx添加到其左侧和右侧坐标并将dy添加到其顶部和底部坐标来抵消该矩形。

void offsetTo(float newLeft, float newTop)

将矩形偏移到特定的(左侧,顶部)位置,并保持其宽度和高度相同。

void readFromParcel(Parcel in)

根据存储在指定宗地中的数据设置矩形的坐标。

void round(Rect dst)

通过将此矩形的坐标四舍五入为最接近的整数值来设置dst整数Rect。

void roundOut(Rect dst)

通过四舍五入“矩阵”来设置dst整数矩形,选择顶部和左侧的楼层以及右侧和底部的天花板。

void set(RectF src)

将来自src的坐标复制到此矩形中。

void set(Rect src)

将来自src的坐标复制到此矩形中。

void set(float left, float top, float right, float bottom)

将矩形的坐标设置为指定的值。

void setEmpty()

将矩形设置为(0,0,0,0)

boolean setIntersect(RectF a, RectF b)

如果矩形a和b相交,则返回true并将此矩形设置为该交点,否则返回false并且不更改此矩形。

void sort()

如果发生翻转,则交换顶部/底部或左/右(即

String toShortString()

以紧凑形式返回矩形的字符串表示形式。

String toString()

返回对象的字符串表示形式。

void union(RectF r)

更新此Rect以包围自身和指定的矩形。

void union(float left, float top, float right, float bottom)

更新此Rect以包围自身和指定的矩形。

void union(float x, float y)

更新此Rect以封闭自身和[x,y]坐标。

final float width()
void writeToParcel(Parcel out, int flags)

将此矩形写入指定的宗地。

Inherited methods

From class java.lang.Object
From interface android.os.Parcelable

Fields

CREATOR

Added in API level 3
Creator<RectF> CREATOR

bottom

Added in API level 1
float bottom

left

Added in API level 1
float left

right

Added in API level 1
float right

top

Added in API level 1
float top

Public constructors

RectF

Added in API level 1
RectF ()

创建一个新的空RectF。 所有的坐标都被初始化为0。

RectF

Added in API level 1
RectF (float left, 
                float top, 
                float right, 
                float bottom)

用指定的坐标创建一个新的矩形。 注意:不执行范围检查,所以调用者必须确保左<=右和顶部<=底部。

Parameters
left float: The X coordinate of the left side of the rectangle
top float: The Y coordinate of the top of the rectangle
right float: The X coordinate of the right side of the rectangle
bottom float: The Y coordinate of the bottom of the rectangle

RectF

Added in API level 1
RectF (RectF r)

创建一个新的矩形,使用指定矩形中的值进行初始化(未作任何修改)。

Parameters
r RectF: The rectangle whose coordinates are copied into the new rectangle.

RectF

Added in API level 1
RectF (Rect r)

Parameters
r Rect

Public methods

centerX

Added in API level 1
float centerX ()

Returns
float the horizontal center of the rectangle. This does not check for a valid rectangle (i.e. left <= right)

centerY

Added in API level 1
float centerY ()

Returns
float the vertical center of the rectangle. This does not check for a valid rectangle (i.e. top <= bottom)

contains

Added in API level 1
boolean contains (float left, 
                float top, 
                float right, 
                float bottom)

如果矩形的4个指定边在此矩形内或等于此矩形,则返回true。 即这个矩形是指定矩形的超集。 一个空矩形永远不会包含另一个矩形。

Parameters
left float: The left side of the rectangle being tested for containment
top float: The top of the rectangle being tested for containment
right float: The right side of the rectangle being tested for containment
bottom float: 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

Added in API level 1
boolean contains (RectF r)

如果指定的矩形r在此矩形内或等于此矩形,则返回true。 一个空矩形永远不会包含另一个矩形。

Parameters
r RectF: The rectangle being tested for containment.
Returns
boolean true iff the specified rectangle r is inside or equal to this rectangle

contains

Added in API level 1
boolean contains (float x, 
                float y)

如果(x,y)在矩形内,则返回true。 左边和顶部被认为是在里面,而右边和底部则不在。 这意味着对于ax,将包含y:left <= x <right并且top <= y <bottom。 一个空矩形永远不会包含任何点。

Parameters
x float: The X coordinate of the point being tested for containment
y float: 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

Added in API level 3
int describeContents ()

Parcelable接口方法

Returns
int a bitmask indicating the set of special object types marshaled by this Parcelable object instance.

equals

Added in API level 1
boolean equals (Object o)

指示其他某个对象是否“等于”这一个。

equals方法对非空对象引用实现等价关系:

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

equals方法Object实现对象上最可能的等价关系; 也就是说,对于任何非空参考值xy ,当且仅当xy引用同一对象( x == y的值为true )时,此方法返回true

请注意,无论何时覆盖此方法,通常都必须覆盖 hashCode方法,以维护 hashCode方法的一般合约,该方法声明相等对象必须具有相同的哈希代码。

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.

hashCode

Added in API level 1
int hashCode ()

返回对象的哈希码值。 为了散列表的好处而支持该方法,例如由HashMap提供的HashMap

hashCode的总合同是:

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

尽可能合理实用,由类Object定义的hashCode方法确实为不同的对象返回不同的整数。 (这通常通过将对象的内部地址转换为整数来实现,但Java TM编程语言不需要此实现技术。)

Returns
int a hash code value for this object.

height

Added in API level 1
float height ()

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

inset

Added in API level 1
void inset (float dx, 
                float dy)

(dx,dy)插入矩形。 如果dx为正值,则边向内移动,使矩形变窄。 如果dx为负值,则边向外移动,使矩形变宽。 dy和顶部和底部也是如此。

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

intersect

Added in API level 1
boolean intersect (RectF r)

如果指定的矩形与此矩形相交,则返回true并将此矩形设置为该交点,否则返回false并不更改此矩形。 不执行检查以查看任一矩形是否为空。 为了测试交集,使用intersects()

Parameters
r RectF: 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

Added in API level 1
boolean intersect (float left, 
                float top, 
                float right, 
                float bottom)

如果由left,top,right,bottom指定的矩形与此矩形相交,则返回true并将此矩形设置为该交点,否则返回false并且不更改此矩形。 不执行检查以查看任一矩形是否为空。 注意:要仅测试相交,请使用intersects()

Parameters
left float: The left side of the rectangle being intersected with this rectangle
top float: The top of the rectangle being intersected with this rectangle
right float: The right side of the rectangle being intersected with this rectangle.
bottom float: 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.

intersects

Added in API level 1
boolean intersects (float left, 
                float top, 
                float right, 
                float bottom)

如果此矩形与指定的矩形相交,则返回true。 这个矩形在任何情况下都不会被修改。 不执行检查以查看任一矩形是否为空。 要记录交集,请使用intersect()或setIntersect()。

Parameters
left float: The left side of the rectangle being tested for intersection
top float: The top of the rectangle being tested for intersection
right float: The right side of the rectangle being tested for intersection
bottom float: 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

Added in API level 1
boolean intersects (RectF a, 
                RectF b)

如果两个指定的矩形相交,则返回true。 在任何情况下都不修改任何一个矩形。 要记录交集,请使用intersect()或setIntersect()。

Parameters
a RectF: The first rectangle being tested for intersection
b RectF: The second rectangle being tested for intersection
Returns
boolean true iff the two specified rectangles intersect. In no event are either of the rectangles modified.

isEmpty

Added in API level 1
boolean isEmpty ()

如果矩形是空的,则返回true(left> = right或top> = bottom)

Returns
boolean

offset

Added in API level 1
void offset (float dx, 
                float dy)

通过将dx添加到其左侧和右侧坐标并将dy添加到其顶部和底部坐标来抵消该矩形。

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

offsetTo

Added in API level 1
void offsetTo (float newLeft, 
                float newTop)

将矩形偏移到特定的(左侧,顶部)位置,并保持其宽度和高度相同。

Parameters
newLeft float: The new "left" coordinate for the rectangle
newTop float: The new "top" coordinate for the rectangle

readFromParcel

Added in API level 3
void readFromParcel (Parcel in)

根据存储在指定宗地中的数据设置矩形的坐标。 要将矩形写入宗地,请调用writeToParcel()。

Parameters
in Parcel: The parcel to read the rectangle's coordinates from

round

Added in API level 1
void round (Rect dst)

通过将此矩形的坐标四舍五入为最接近的整数值来设置dst整数Rect。

Parameters
dst Rect

roundOut

Added in API level 1
void roundOut (Rect dst)

通过四舍五入“矩阵”来设置dst整数矩形,选择顶部和左侧的楼层以及右侧和底部的天花板。

Parameters
dst Rect

set

Added in API level 1
void set (RectF src)

将来自src的坐标复制到此矩形中。

Parameters
src RectF: The rectangle whose coordinates are copied into this rectangle.

set

Added in API level 1
void set (Rect src)

将来自src的坐标复制到此矩形中。

Parameters
src Rect: The rectangle whose coordinates are copied into this rectangle.

set

Added in API level 1
void set (float left, 
                float top, 
                float right, 
                float bottom)

将矩形的坐标设置为指定的值。 注意:不执行范围检查,因此由调用者确保左<=右和顶部<=底部。

Parameters
left float: The X coordinate of the left side of the rectangle
top float: The Y coordinate of the top of the rectangle
right float: The X coordinate of the right side of the rectangle
bottom float: The Y coordinate of the bottom of the rectangle

setEmpty

Added in API level 1
void setEmpty ()

将矩形设置为(0,0,0,0)

setIntersect

Added in API level 1
boolean setIntersect (RectF a, 
                RectF b)

如果矩形a和b相交,则返回true并将此矩形设置为该交点,否则返回false并且不更改此矩形。 不执行检查以查看任一矩形是否为空。 为了测试交集,使用intersects()

Parameters
a RectF: The first rectangle being intersected with
b RectF: The second rectangle being intersected with
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

Added in API level 1
void sort ()

如果翻转(即,左>右和/或顶部>底部),交换顶部/底部或左/右。 如果边是分开计算的,并且可能相互交叉,则可以调用它。 如果边缘已经是正确的(即左边<=右边和顶部<=底部),则不做任何事情。

toShortString

Added in API level 14
String toShortString ()

以紧凑形式返回矩形的字符串表示形式。

Returns
String

toString

Added in API level 1
String toString ()

返回对象的字符串表示形式。 一般来说, toString方法返回一个“文本表示”该对象的字符串。 结果应该是一个简洁但内容丰富的表述,对于一个人来说很容易阅读。 建议所有子类重写此方法。

ObjecttoString方法返回一个字符串,其中包含对象为实例的类的名称,符号字符“ @ ”以及对象的哈希代码的无符号十六进制表示形式。 换句话说,这个方法返回一个字符串,其值等于:

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

Returns
String a string representation of the object.

union

Added in API level 1
void union (RectF r)

更新此Rect以包围自身和指定的矩形。 如果指定的矩形为空,则不做任何操作。 如果该矩形为空,则将其设置为指定的矩形。

Parameters
r RectF: The rectangle being unioned with this rectangle

union

Added in API level 1
void union (float left, 
                float top, 
                float right, 
                float bottom)

更新此Rect以包围自身和指定的矩形。 如果指定的矩形为空,则不做任何操作。 如果该矩形为空,则将其设置为指定的矩形。

Parameters
left float: The left edge being unioned with this rectangle
top float: The top edge being unioned with this rectangle
right float: The right edge being unioned with this rectangle
bottom float: The bottom edge being unioned with this rectangle

union

Added in API level 1
void union (float x, 
                float y)

更新此Rect以封闭自身和[x,y]坐标。 没有检查,看看这个矩形是非空的。

Parameters
x float: The x coordinate of the point to add to the rectangle
y float: The y coordinate of the point to add to the rectangle

width

Added in API level 1
float width ()

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

writeToParcel

Added in API level 3
void writeToParcel (Parcel out, 
                int flags)

将此矩形写入指定的宗地。 要从包中恢复矩形,请使用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_WRITE_RETURN_VALUE.

Hooray!