Most visited

Recently visited

Added in API level 1

View.MeasureSpec

public static class View.MeasureSpec
extends Object

java.lang.Object
   ↳ android.view.View.MeasureSpec


MeasureSpec封装了从父到子传递的布局需求。 每个MeasureSpec代表宽度或高度的要求。 MeasureSpec由大小和模式组成。 有三种可能的模式:

UNSPECIFIED
The parent has not imposed any constraint on the child. It can be whatever size it wants.
EXACTLY
The parent has determined an exact size for the child. The child is going to be given those bounds regardless of how big it wants to be.
AT_MOST
The child can be as large as it wants up to the specified size.
MeasureSpecs are implemented as ints to reduce object allocation. This class is provided to pack and unpack the <size, mode> tuple into the int.

Summary

Constants

int AT_MOST

测量规格模式:孩子可以达到想要的规模,达到指定的尺寸。

int EXACTLY

衡量规格模式:父母确定了孩子的确切尺寸。

int UNSPECIFIED

衡量规格模式:父母没有对孩子施加任何限制。

Public constructors

View.MeasureSpec()

Public methods

static int getMode(int measureSpec)

从提供的度量指标中提取模式。

static int getSize(int measureSpec)

从提供的度量指标中提取大小。

static int makeMeasureSpec(int size, int mode)

根据提供的尺寸和模式创建度量指定。

static String toString(int measureSpec)

返回指定度量指定的字符串表示。

Inherited methods

From class java.lang.Object

Constants

AT_MOST

Added in API level 1
int AT_MOST

测量规格模式:孩子可以达到想要的规模,达到指定的尺寸。

常量值:-2147483648(0x80000000)

EXACTLY

Added in API level 1
int EXACTLY

衡量规格模式:父母确定了孩子的确切尺寸。 无论孩子想要多大,孩子都会得到这些界限。

常量值:1073741824(0x40000000)

UNSPECIFIED

Added in API level 1
int UNSPECIFIED

衡量规格模式:父母没有对孩子施加任何限制。 它可以是任何大小,它想要的。

常量值:0(0x00000000)

Public constructors

View.MeasureSpec

Added in API level 1
View.MeasureSpec ()

Public methods

getMode

Added in API level 1
int getMode (int measureSpec)

从提供的度量指标中提取模式。

Parameters
measureSpec int: the measure specification to extract the mode from
Returns
int UNSPECIFIED, AT_MOST or EXACTLY

getSize

Added in API level 1
int getSize (int measureSpec)

从提供的度量指标中提取大小。

Parameters
measureSpec int: the measure specification to extract the size from
Returns
int the size in pixels defined in the supplied measure specification

makeMeasureSpec

Added in API level 1
int makeMeasureSpec (int size, 
                int mode)

根据提供的尺寸和模式创建度量指定。 该模式必须始终为以下之一:

注意:在API级别17和更低级别,makeMeasureSpec的实现是这样的,即参数的顺序无关紧要,任何一个值的溢出都可能影响产生的MeasureSpec。 RelativeLayout受此错误影响。 目标API级别大于17的应用将获得固定的,更严格的行为。

Parameters
size int: the size of the measure specification
mode int: the mode of the measure specification
Returns
int the measure specification based on size and mode

toString

Added in API level 1
String toString (int measureSpec)

返回指定度量指定的字符串表示。

Parameters
measureSpec int: the measure specification to convert to a String
Returns
String a String with the following format: "MeasureSpec: MODE SIZE"

Hooray!