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在每个单元组中支持行和列的跨越和任意形式的对齐。 与每个单元组相关的基本参数被收集到它们的垂直和水平分量中,并存储在rowSpec
和columnSpec
布局参数中。 Specs
是不可变的结构,可以在不同孩子的布局参数之间共享。
行和列规格包含沿每个轴的前导索引和尾随索引,并一起指定划分此单元组的单元格的四个网格索引。
行和列规格的对齐属性一起指定单元组内对齐的两个方面。 也可以使用setGravity(int)
方法在其单元组内指定子对齐。
Weight属性也包含在Spec中,并指定由于相关视图而导致的多余空间的比例。
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
.
WRAP_CONTENT
or
MATCH_PARENT
when configuring the children of a GridLayout.
width
= WRAP_CONTENT
height
= WRAP_CONTENT
topMargin
= 0 when useDefaultMargins
is false
; otherwise UNDEFINED
, to indicate that a default value should be computed on demand. leftMargin
= 0 when useDefaultMargins
is false
; otherwise UNDEFINED
, to indicate that a default value should be computed on demand. bottomMargin
= 0 when useDefaultMargins
is false
; otherwise UNDEFINED
, to indicate that a default value should be computed on demand. rightMargin
= 0 when useDefaultMargins
is false
; otherwise UNDEFINED
, to indicate that a default value should be computed on demand. rowSpec
.row
= UNDEFINED
rowSpec
.rowSpan
= 1 rowSpec
.alignment
= BASELINE
rowSpec
.weight
= 0 columnSpec
.column
= UNDEFINED
columnSpec
.columnSpan
= 1 columnSpec
.alignment
= START
columnSpec
.weight
= 0 GridLayout
for a more complete description of the conventions used by GridLayout in the interpretation of the properties of this class.
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) 为此 |
|
GridLayout.LayoutParams() 使用 |
|
GridLayout.LayoutParams(ViewGroup.LayoutParams params) |
|
GridLayout.LayoutParams(ViewGroup.MarginLayoutParams params) |
|
GridLayout.LayoutParams(GridLayout.LayoutParams source) 复制构造函数。 |
|
GridLayout.LayoutParams(Context context, AttributeSet attrs) 属性集中未定义的值采用 |
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
|
列边界定界该视图占用的单元格组的左侧。
必须是整数值,例如“ 100
”。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name
”)或主题属性(形式为“ ?[package:][type:]name
”)的 ?[package:][type:]name
。
这对应于全局属性资源符号 layout_column
。
列跨度:界定该视图占用的单元格组的右侧和左侧边界之间的差异。 默认值是1。 见GridLayout.Spec
。
必须是整数值,例如“ 100
”。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name
”)或主题属性(形式为“ ?[package:][type:]name
”)的 ?[package:][type:]name
。
这对应于全局属性资源符号 layout_columnSpan
。
在空间分配过剩时应分配给此视图的水平空间的相对比例。
必须是浮点值,例如“ 1.2
”。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name
”)或主题属性(形式为“ ?[package:][type:]name
”)的 ?[package:][type:]name
。
这对应于全局属性资源符号 layout_columnWeight
。
重力指定组件应该如何放置在其组单元中。 默认值是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
。
相关方法:
行边界划定了该视图所占用的一组单元格的顶部。
必须是整数值,例如“ 100
”。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name
”)或主题属性(形式为“ ?[package:][type:]name
”)的 ?[package:][type:]name
。
这对应于全局属性资源符号 layout_row
。
行跨度:界定该视图占用的单元格组的顶部和底部边界之间的差异。 默认值是1。 见GridLayout.Spec
。
必须是整数值,例如“ 100
”。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name
”)或主题属性(形式为“ ?[package:][type:]name
”)的 ?[package:][type:]name
。
这对应于全局属性资源符号 layout_rowSpan
。
在空间分配过剩时应分配给此视图的垂直空间的相对比例。
必须是浮点值,例如“ 1.2
”。
这也可能是对包含此类型值的资源(形式为“ @[package:]type:name
”)或主题属性(形式为“ ?[package:][type:]name
”)的 ?[package:][type:]name
。
这对应于全局属性资源符号 layout_rowWeight
。
GridLayout.Spec columnSpec
定义这些布局参数描述的单元组的水平特性的规范。 如果在测量或布局操作完成后对此字段进行分配,则必须调用setLayoutParams(ViewGroup.LayoutParams)
以通知GridLayout该更改。 GridLayout通常能够检测代码未能遵守这一规则,发出警告并采取措施补偿遗漏。 该设施以尽力而为的方式实施,不应依赖于生产代码 - 因此最好包括上述呼吁,以便在实际情况下立即删除警告。
GridLayout.Spec rowSpec
定义这些布局参数所描述的单元组的垂直特性的规范。 如果在测量或布局操作完成后对此字段进行分配,则必须致电setLayoutParams(ViewGroup.LayoutParams)
以通知GridLayout该更改。 GridLayout通常能够检测代码未能遵守这一规则,发出警告并采取措施补偿遗漏。 该设施以尽力而为的方式实施,不应依赖于生产代码 - 因此最好包括上述呼吁,以便在实际情况下立即删除警告。
GridLayout.LayoutParams (GridLayout.Spec rowSpec, GridLayout.Spec columnSpec)
为此rowSpec
和columnSpec
构造一个新的LayoutParams实例。 所有其他字段都使用GridLayout.LayoutParams
定义的默认值进行初始化。
Parameters | |
---|---|
rowSpec |
GridLayout.Spec : the rowSpec |
columnSpec |
GridLayout.Spec : the columnSpec |
GridLayout.LayoutParams ()
使用 GridLayout.LayoutParams
定义的默认值构造新的LayoutParams。
GridLayout.LayoutParams (ViewGroup.LayoutParams params)
Parameters | |
---|---|
params |
ViewGroup.LayoutParams
|
GridLayout.LayoutParams (ViewGroup.MarginLayoutParams params)
Parameters | |
---|---|
params |
ViewGroup.MarginLayoutParams
|
GridLayout.LayoutParams (GridLayout.LayoutParams source)
复制构造函数。 克隆源的宽度,高度,边距值,行规格和列规格。
Parameters | |
---|---|
source |
GridLayout.LayoutParams : The layout params to copy from. |
GridLayout.LayoutParams (Context context, AttributeSet attrs)
未在属性集中定义的值采用 GridLayout.LayoutParams
定义的默认值。
Parameters | |
---|---|
context |
Context
|
attrs |
AttributeSet
|
boolean equals (Object o)
指示其他某个对象是否“等于”这一个。
equals
方法在非空对象引用上实现等价关系:
x
, x.equals(x)
should return true
. x
and y
, x.equals(y)
should return true
if and only if y.equals(x)
returns true
. x
, y
, and z
, if x.equals(y)
returns true
and y.equals(z)
returns true
, then x.equals(z)
should return true
. 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. x
, x.equals(null)
should return false
. 类Object
的equals
方法实现了对象上最可能的等价关系; 也就是说,对于任何非空参考值x
和y
,当且仅当x
和y
引用同一对象( 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. |
int hashCode ()
返回对象的哈希码值。 为了散列表的好处而支持该方法,例如由HashMap
提供的HashMap
。
hashCode
的总合同是:
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. equals(Object)
method, then calling the hashCode
method on each of the two objects must produce the same integer result. 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. |
void setGravity (int gravity)
介绍子视图的定位方式。 默认是LEFT | BASELINE
。 见Gravity
。
相关XML属性:
Parameters | |
---|---|
gravity |
int : the new gravity value |
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 |