Most visited

Recently visited

Added in API level 21

Size

public final class Size
extends Object

java.lang.Object
   ↳ android.util.Size


用于描述像素宽度和高度尺寸的不可变类。

Summary

Public constructors

Size(int width, int height)

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

Public methods

boolean equals(Object obj)

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

int getHeight()

获取大小的高度(以像素为单位)。

int getWidth()

获取大小的宽度(以像素为单位)。

int hashCode()

返回对象的哈希码值。

static Size parseSize(String string)

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

String toString()

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

Inherited methods

From class java.lang.Object

Public constructors

Size

Added in API level 21
Size (int width, 
                int height)

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

Parameters
width int: The width of the size, in pixels
height int: The height of the size, in pixels

Public methods

equals

Added in API level 21
boolean equals (Object obj)

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

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

大小对象永远不会等于任何其他类型的对象。

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

获取大小的高度(以像素为单位)。

Returns
int height

getWidth

Added in API level 21
int getWidth ()

获取大小的宽度(以像素为单位)。

Returns
int 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.

parseSize

Added in API level 21
Size parseSize (String string)

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

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

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

宽度 x 高度 ”或“ 宽度 * 高度=> new Size(width, height) ,其中 宽度高度是可能包含符号(例如“-10”,“+7”或“5”)的字符串整数。

Size.parseSize("3*+6").equals(new Size(3, 6)) == true
 Size.parseSize("-3x-6").equals(new Size(-3, -6)) == true
 Size.parseSize("4 by 3") => throws NumberFormatException
 

Parameters
string String: the string representation of a size value.
Returns
Size 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!