Most visited

Recently visited

Added in API level 21

SizeF

public final class SizeF
extends Object

java.lang.Object
   ↳ android.util.SizeF


用于描述某些任意单位的宽度和高度尺寸的不可变类。

宽度和高度是作为浮点表示存储的有限值。

Summary

Public constructors

SizeF(float width, float height)

创建一个新的不可变的SizeF实例。

Public methods

boolean equals(Object obj)

检查这个大小是否等于另一个大小。

float getHeight()

获取大小的高度(作为任意单位)。

float getWidth()

获取大小的宽度(作为任意单位)。

int hashCode()

返回对象的哈希码值。

static SizeF parseSizeF(String string)

将指定的字符串解析为大小值。

String toString()

返回格式为 "WxH"的字符串

Inherited methods

From class java.lang.Object

Public constructors

SizeF

Added in API level 21
SizeF (float width, 
                float height)

创建一个新的不可变的SizeF实例。

widthheight必须是有限数字。 特别是, NaN和正/负无穷是非法值。

Parameters
width float: The width of the size
height float: The height of the size
Throws
IllegalArgumentException if either width or height was not finite.

Public methods

equals

Added in API level 21
boolean equals (Object obj)

检查这个大小是否等于另一个大小。

当且仅当两个尺寸的宽度和高度相同时,两种尺寸相等。

为此,当且仅当方法 floatToIntBits(float)在应用于每个值时返回相同的 int值时,宽度/高度浮点值 floatToIntBits(float)相同。

Parameters
obj Object: the reference object with which to compare.
Returns
boolean true if the objects were equal, false otherwise

getHeight

Added in API level 21
float getHeight ()

获取大小的高度(作为任意单位)。

Returns
float height

getWidth

Added in API level 21
float getWidth ()

获取大小的宽度(作为任意单位)。

Returns
float width

hashCode

Added in API level 21
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.

parseSizeF

Added in API level 21
SizeF parseSizeF (String string)

将指定的字符串解析为大小值。

ASCII字符 \ u002a ('*')和 \ u0078 ('x')被识别为宽度和高度之间的分隔符。

对于任何SizeF sSizeF.parseSizeF(s.toString()).equals(s) 但是,该方法还处理以下列形式表示的大小:

宽度 x 高度 ”或“ 宽度 * 高度=> new SizeF(width, height) ,其中 宽度高度是可能包含符号(如“-10.3”,“+7”或“5.2”但不包含 'x' (例如以十六进制字符串格式浮动)。

SizeF.parseSizeF("3.2*+6").equals(new SizeF(3.2f, 6.0f)) == true
 SizeF.parseSizeF("-3x-6").equals(new SizeF(-3.0f, -6.0f)) == true
 SizeF.parseSizeF("4 by 3") => throws NumberFormatException
 

Parameters
string String: the string representation of a size value.
Returns
SizeF the size value represented by string.
Throws
NumberFormatException if string cannot be parsed as a size value.
NullPointerException if string was null

toString

Added in API level 21
String toString ()

返回格式为 "WxH"的字符串

Returns
String string representation of the size

Hooray!