Most visited

Recently visited

Added in API level 14

GridLayout.LayoutParams

public static class GridLayout.LayoutParams
extends ViewGroup.MarginLayoutParams

java.lang.Object
   ↳ android.view.ViewGroup.LayoutParams
     ↳ android.view.ViewGroup.MarginLayoutParams
       ↳ android.widget.GridLayout.LayoutParams


布局信息与GridLayout的每个子节点相关联。

GridLayout在每个单元组中支持行和列的跨越和任意形式的对齐。 与每个单元组相关的基本参数被收集到它们的垂直和水平分量中,并存储在rowSpeccolumnSpec布局参数中。 Specs是不可变的结构,可以在不同孩子的布局参数之间共享。

行和列规格包含沿每个轴的前导索引和尾随索引,并一起指定划分此单元组的单元格的四个网格索引。

行和列规格的对齐属性一起指定单元组内对齐的两个方面。 也可以使用setGravity(int)方法在其单元组内指定子对齐。

Weight属性也包含在Spec中,并指定由于相关视图而导致的多余空间的比例。

WRAP_CONTENT and MATCH_PARENT

Because the default values of the width and height properties are both WRAP_CONTENT, this value never needs to be explicitly declared in the layout parameters of GridLayout's children. In addition, GridLayout does not distinguish the special size value MATCH_PARENT from WRAP_CONTENT. A component's ability to expand to the size of the parent is instead controlled by the principle of flexibility, as discussed in GridLayout.

Summary

You should not need to use either of the special size values: WRAP_CONTENT or MATCH_PARENT when configuring the children of a GridLayout.

Default values

See GridLayout for a more complete description of the conventions used by GridLayout in the interpretation of the properties of this class.

Summary

XML attributes

android:layout_column The column boundary delimiting the left of the group of cells occupied by this view. 
android:layout_columnSpan The column span: the difference between the right and left boundaries delimiting the group of cells occupied by this view. 
android:layout_columnWeight The relative proportion of horizontal space that should be allocated to this view during excess space distribution. 
android:layout_gravity Gravity specifies how a component should be placed in its group of cells. 
android:layout_row The row boundary delimiting the top of the group of cells occupied by this view. 
android:layout_rowSpan The row span: the difference between the top and bottom boundaries delimiting the group of cells occupied by this view. 
android:layout_rowWeight The relative proportion of vertical space that should be allocated to this view during excess space distribution. 

Inherited XML attributes

From class android.view.ViewGroup.MarginLayoutParams
From class android.view.ViewGroup.LayoutParams

Inherited constants

From class android.view.ViewGroup.LayoutParams

Fields

public GridLayout.Spec columnSpec

定义这些布局参数描述的单元组的水平特性的规范。

public GridLayout.Spec rowSpec

定义这些布局参数所描述的单元组的垂直特性的规范。

Inherited fields

From class android.view.ViewGroup.MarginLayoutParams
From class android.view.ViewGroup.LayoutParams

Public constructors

GridLayout.LayoutParams(GridLayout.Spec rowSpec, GridLayout.Spec columnSpec)

为此 rowSpeccolumnSpec构造一个新的LayoutParams实例。

GridLayout.LayoutParams()

使用 GridLayout.LayoutParams定义的默认值构造一个新的LayoutParams。

GridLayout.LayoutParams(ViewGroup.LayoutParams params)

GridLayout.LayoutParams(ViewGroup.MarginLayoutParams params)

GridLayout.LayoutParams(GridLayout.LayoutParams source)

复制构造函数。

GridLayout.LayoutParams(Context context, AttributeSet attrs)

属性集中未定义的值采用 GridLayout.LayoutParams定义的默认值。

Public methods

boolean equals(Object o)

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

int hashCode()

返回对象的哈希码值。

void setGravity(int gravity)

介绍子视图的定位方式。

Protected methods

void setBaseAttributes(TypedArray attributes, int widthAttr, int heightAttr)

从提供的属性中提取布局参数。

Inherited methods

From class android.view.ViewGroup.MarginLayoutParams
From class android.view.ViewGroup.LayoutParams
From class java.lang.Object

XML attributes

android:layout_column

列边界定界该视图占用的单元格组的左侧。

必须是整数值,例如“ 100 ”。

这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name

这对应于全局属性资源符号 layout_column

android:layout_columnSpan

列跨度:界定该视图占用的单元格组的右侧和左侧边界之间的差异。 默认值是1。 GridLayout.Spec

必须是整数值,例如“ 100 ”。

这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name

这对应于全局属性资源符号 layout_columnSpan

android:layout_columnWeight

在空间分配过剩时应分配给此视图的水平空间的相对比例。

必须是浮点值,例如“ 1.2 ”。

这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name

这对应于全局属性资源符号 layout_columnWeight

android:layout_gravity

重力指定组件应该如何放置在其组单元中。 默认值是LEFT | 基线。 setGravity(int)

必须是以下常量值中的一个或多个(用'|'分隔)。

Constant Value 描述
top 0x30 Push object to the top of its container, not changing its size.
bottom 0x50 Push object to the bottom of its container, not changing its size.
left 0x03 Push object to the left of its container, not changing its size.
right 0x05 Push object to the right of its container, not changing its size.
center_vertical 0x10 Place object in the vertical center of its container, not changing its size.
fill_vertical 0x70 Grow the vertical size of the object if needed so it completely fills its container.
center_horizontal 0x01 Place object in the horizontal center of its container, not changing its size.
fill_horizontal 0x07 Grow the horizontal size of the object if needed so it completely fills its container.
center 0x11 Place the object in the center of its container in both the vertical and horizontal axis, not changing its size.
fill 0x77 Grow the horizontal and vertical size of the object if needed so it completely fills its container.
clip_vertical 0x80 Additional option that can be set to have the top and/or bottom edges of the child clipped to its container's bounds. The clip will be based on the vertical gravity: a top gravity will clip the bottom edge, a bottom gravity will clip the top edge, and neither will clip both edges.
clip_horizontal 0x08 Additional option that can be set to have the left and/or right edges of the child clipped to its container's bounds. The clip will be based on the horizontal gravity: a left gravity will clip the right edge, a right gravity will clip the left edge, and neither will clip both edges.
start 0x00800003 Push object to the beginning of its container, not changing its size.
end 0x00800005 Push object to the end of its container, not changing its size.

这对应于全局属性资源符号 layout_gravity

相关方法:

android:layout_row

行边界划定了该视图所占用的一组单元格的顶部。

必须是整数值,例如“ 100 ”。

这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name

这对应于全局属性资源符号 layout_row

android:layout_rowSpan

行跨度:界定该视图占用的单元格组的顶部和底部边界之间的差异。 默认值是1。 GridLayout.Spec

必须是整数值,例如“ 100 ”。

这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name

这对应于全局属性资源符号 layout_rowSpan

android:layout_rowWeight

在空间分配过剩时应分配给此视图的垂直空间的相对比例。

必须是浮点值,例如“ 1.2 ”。

这也可能是对包含此类型值的资源(形式为“ @[package:]type:name ”)或主题属性(形式为“ ?[package:][type:]name ”)的 ?[package:][type:]name

这对应于全局属性资源符号 layout_rowWeight

Fields

columnSpec

Added in API level 14
GridLayout.Spec columnSpec

定义这些布局参数描述的单元组的水平特性的规范。 如果在测量或布局操作完成后对此字段进行分配,则必须调用setLayoutParams(ViewGroup.LayoutParams)以通知GridLayout该更改。 GridLayout通常能够检测代码未能遵守这一规则,发出警告并采取措施补偿遗漏。 该设施以尽力而为的方式实施,不应依赖于生产代码 - 因此最好包括上述呼吁,以便在实际情况下立即删除警告。

rowSpec

Added in API level 14
GridLayout.Spec rowSpec

定义这些布局参数所描述的单元组的垂直特性的规范。 如果在测量或布局操作完成后对此字段进行分配,则必须致电setLayoutParams(ViewGroup.LayoutParams)以通知GridLayout该更改。 GridLayout通常能够检测代码未能遵守这一规则,发出警告并采取措施补偿遗漏。 该设施以尽力而为的方式实施,不应依赖于生产代码 - 因此最好包括上述呼吁,以便在实际情况下立即删除警告。

Public constructors

GridLayout.LayoutParams

Added in API level 14
GridLayout.LayoutParams (GridLayout.Spec rowSpec, 
                GridLayout.Spec columnSpec)

为此rowSpeccolumnSpec构造一个新的LayoutParams实例。 所有其他字段都使用GridLayout.LayoutParams定义的默认值进行初始化。

Parameters
rowSpec GridLayout.Spec: the rowSpec
columnSpec GridLayout.Spec: the columnSpec

GridLayout.LayoutParams

Added in API level 14
GridLayout.LayoutParams ()

使用 GridLayout.LayoutParams定义的默认值构造新的LayoutParams。

GridLayout.LayoutParams

Added in API level 14
GridLayout.LayoutParams (ViewGroup.LayoutParams params)

Parameters
params ViewGroup.LayoutParams

GridLayout.LayoutParams

Added in API level 14
GridLayout.LayoutParams (ViewGroup.MarginLayoutParams params)

Parameters
params ViewGroup.MarginLayoutParams

GridLayout.LayoutParams

Added in API level 14
GridLayout.LayoutParams (GridLayout.LayoutParams source)

复制构造函数。 克隆源的宽度,高度,边距值,行规格和列规格。

Parameters
source GridLayout.LayoutParams: The layout params to copy from.

GridLayout.LayoutParams

Added in API level 14
GridLayout.LayoutParams (Context context, 
                AttributeSet attrs)

未在属性集中定义的值采用 GridLayout.LayoutParams定义的默认值。

Parameters
context Context
attrs AttributeSet

Public methods

equals

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

Objectequals方法实现了对象上最可能的等价关系; 也就是说,对于任何非空参考值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 14
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.

setGravity

Added in API level 14
void setGravity (int gravity)

介绍子视图的定位方式。 默认是LEFT | BASELINE Gravity

相关XML属性:

Parameters
gravity int: the new gravity value

Protected methods

setBaseAttributes

Added in API level 14
void setBaseAttributes (TypedArray attributes, 
                int widthAttr, 
                int heightAttr)

从提供的属性中提取布局参数。

Parameters
attributes TypedArray: the style attributes to extract the parameters from
widthAttr int: the identifier of the width attribute
heightAttr int: the identifier of the height attribute

Hooray!