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 |
Layout information associated with each of the children of a GridLayout.
GridLayout supports both row and column spanning and arbitrary forms of alignment within
each cell group. The fundamental parameters associated with each cell group are
gathered into their vertical and horizontal components and stored
in the rowSpec
and columnSpec
layout parameters.
Specs
are immutable structures
and may be shared between the layout parameters of different children.
The row and column specs contain the leading and trailing indices along each axis and together specify the four grid indices that delimit the cells of this cell group.
The alignment properties of the row and column specs together specify
both aspects of alignment within the cell group. It is also possible to specify a child's
alignment within its cell group by using the GridLayout.LayoutParams#setGravity(int)
method.
The weight property is also included in Spec and specifies the proportion of any excess space that is due to the associated view.
WRAP_CONTENT and MATCH_PARENT
Because the default values of theViewGroup.LayoutParams.width
and ViewGroup.LayoutParams.height
properties are both ViewGroup.LayoutParams.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 ViewGroup.LayoutParams.MATCH_PARENT
from
ViewGroup.LayoutParams.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
ViewGroup.LayoutParams.width
=ViewGroup.LayoutParams.WRAP_CONTENT
ViewGroup.LayoutParams.height
=ViewGroup.LayoutParams.WRAP_CONTENT
ViewGroup.MarginLayoutParams.topMargin
= 0 whenuseDefaultMargins
isfalse
; otherwiseGridLayout.UNDEFINED
, to indicate that a default value should be computed on demand.ViewGroup.MarginLayoutParams.leftMargin
= 0 whenuseDefaultMargins
isfalse
; otherwiseGridLayout.UNDEFINED
, to indicate that a default value should be computed on demand.ViewGroup.MarginLayoutParams.bottomMargin
= 0 whenuseDefaultMargins
isfalse
; otherwiseGridLayout.UNDEFINED
, to indicate that a default value should be computed on demand.ViewGroup.MarginLayoutParams.rightMargin
= 0 whenuseDefaultMargins
isfalse
; otherwiseGridLayout.UNDEFINED
, to indicate that a default value should be computed on demand.rowSpec
.row
=GridLayout.UNDEFINED
rowSpec
.rowSpan
= 1rowSpec
.alignment
=GridLayout.BASELINE
rowSpec
.weight
= 0columnSpec
.column
=GridLayout.UNDEFINED
columnSpec
.columnSpan
= 1columnSpec
.alignment
=GridLayout.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.
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 | |
---|---|
Inherited constants |
---|
Fields | |
---|---|
public
GridLayout.Spec |
columnSpec
The spec that defines the horizontal characteristics of the cell group described by these layout parameters. |
public
GridLayout.Spec |
rowSpec
The spec that defines the vertical characteristics of the cell group described by these layout parameters. |
Inherited fields |
---|
Public constructors | |
---|---|
LayoutParams(GridLayout.Spec rowSpec, GridLayout.Spec columnSpec)
Constructs a new LayoutParams instance for this |
|
LayoutParams()
Constructs a new LayoutParams with default values as defined in |
|
LayoutParams(ViewGroup.LayoutParams params)
|
|
LayoutParams(ViewGroup.MarginLayoutParams params)
|
|
LayoutParams(GridLayout.LayoutParams source)
Copy constructor. |
|
LayoutParams(Context context, AttributeSet attrs)
Values not defined in the attribute set take the default values
defined in |
Public methods | |
---|---|
boolean
|
equals(Object o)
Indicates whether some other object is "equal to" this one. |
int
|
hashCode()
Returns a hash code value for the object. |
void
|
setGravity(int gravity)
Describes how the child views are positioned. |
Protected methods | |
---|---|
void
|
setBaseAttributes(TypedArray attributes, int widthAttr, int heightAttr)
Extracts the layout parameters from the supplied attributes. |
Inherited methods | |
---|---|
XML attributes
android:layout_column
The column boundary delimiting the left of the group of cells occupied by this view.
May be an integer value, such as "100
".
android:layout_columnSpan
The column span: the difference between the right and left
boundaries delimiting the group of cells occupied by this view.
The default is one.
See GridLayout.Spec
.
May be an integer value, such as "100
".
android:layout_columnWeight
The relative proportion of horizontal space that should be allocated to this view during excess space distribution.
May be a floating point value, such as "1.2
".
android:layout_gravity
Gravity specifies how a component should be placed in its group of cells.
The default is LEFT | BASELINE.
See GridLayout.LayoutParams.setGravity(int)
.
Must be one or more (separated by '|') of the following constant values.
Constant | Value | Description |
---|---|---|
bottom | 50 | Push object to the bottom of its container, not changing its size. |
center | 11 | Place the object in the center of its container in both the vertical and horizontal axis, not changing its size. |
center_horizontal | 1 | Place object in the horizontal center of its container, not changing its size. |
center_vertical | 10 | Place object in the vertical center of its container, not changing its size. |
clip_horizontal | 8 | 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. |
clip_vertical | 80 | 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. |
end | 800005 | Push object to the end of its container, not changing its size. |
fill | 77 | Grow the horizontal and vertical size of the object if needed so it completely fills its container. |
fill_horizontal | 7 | Grow the horizontal size of the object if needed so it completely fills its container. |
fill_vertical | 70 | Grow the vertical size of the object if needed so it completely fills its container. |
left | 3 | Push object to the left of its container, not changing its size. |
right | 5 | Push object to the right of its container, not changing its size. |
start | 800003 | Push object to the beginning of its container, not changing its size. |
top | 30 | Push object to the top of its container, not changing its size. |
Related methods:
android:layout_row
The row boundary delimiting the top of the group of cells occupied by this view.
May be an integer value, such as "100
".
android:layout_rowSpan
The row span: the difference between the top and bottom
boundaries delimiting the group of cells occupied by this view.
The default is one.
See GridLayout.Spec
.
May be an integer value, such as "100
".
android:layout_rowWeight
The relative proportion of vertical space that should be allocated to this view during excess space distribution.
May be a floating point value, such as "1.2
".
Fields
columnSpec
public GridLayout.Spec columnSpec
The spec that defines the horizontal characteristics of the cell group
described by these layout parameters.
If an assignment is made to this field after a measurement or layout operation
has already taken place, a call to
ViewGroup#setLayoutParams(ViewGroup.LayoutParams)
must be made to notify GridLayout of the change. GridLayout is normally able
to detect when code fails to observe this rule, issue a warning and take steps to
compensate for the omission. This facility is implemented on a best effort basis
and should not be relied upon in production code - so it is best to include the above
calls to remove the warnings as soon as it is practical.
rowSpec
public GridLayout.Spec rowSpec
The spec that defines the vertical characteristics of the cell group
described by these layout parameters.
If an assignment is made to this field after a measurement or layout operation
has already taken place, a call to
ViewGroup#setLayoutParams(ViewGroup.LayoutParams)
must be made to notify GridLayout of the change. GridLayout is normally able
to detect when code fails to observe this rule, issue a warning and take steps to
compensate for the omission. This facility is implemented on a best effort basis
and should not be relied upon in production code - so it is best to include the above
calls to remove the warnings as soon as it is practical.
Public constructors
LayoutParams
public LayoutParams (GridLayout.Spec rowSpec, GridLayout.Spec columnSpec)
Constructs a new LayoutParams instance for this rowSpec
and columnSpec
. All other fields are initialized with
default values as defined in LayoutParams
.
Parameters | |
---|---|
rowSpec |
GridLayout.Spec : the rowSpec |
columnSpec |
GridLayout.Spec : the columnSpec |
LayoutParams
public LayoutParams ()
Constructs a new LayoutParams with default values as defined in LayoutParams
.
LayoutParams
public LayoutParams (ViewGroup.LayoutParams params)
Parameters | |
---|---|
params |
ViewGroup.LayoutParams |
LayoutParams
public LayoutParams (ViewGroup.MarginLayoutParams params)
Parameters | |
---|---|
params |
ViewGroup.MarginLayoutParams |
LayoutParams
public LayoutParams (GridLayout.LayoutParams source)
Copy constructor. Clones the width, height, margin values, row spec, and column spec of the source.
Parameters | |
---|---|
source |
GridLayout.LayoutParams : The layout params to copy from. |
LayoutParams
public LayoutParams (Context context, AttributeSet attrs)
Values not defined in the attribute set take the default values
defined in LayoutParams
.
Parameters | |
---|---|
context |
Context |
attrs |
AttributeSet |
Public methods
equals
public boolean equals (Object o)
Indicates whether some other object is "equal to" this one.
The equals
method implements an equivalence relation
on non-null object references:
- It is reflexive: for any non-null reference value
x
,x.equals(x)
should returntrue
. - It is symmetric: for any non-null reference values
x
andy
,x.equals(y)
should returntrue
if and only ify.equals(x)
returnstrue
. - It is transitive: for any non-null reference values
x
,y
, andz
, ifx.equals(y)
returnstrue
andy.equals(z)
returnstrue
, thenx.equals(z)
should returntrue
. - It is consistent: for any non-null reference values
x
andy
, multiple invocations ofx.equals(y)
consistently returntrue
or consistently returnfalse
, provided no information used inequals
comparisons on the objects is modified. - For any non-null reference value
x
,x.equals(null)
should returnfalse
.
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.
Parameters | |
---|---|
o |
Object : This value may be null . |
Returns | |
---|---|
boolean |
true if this object is the same as the obj
argument; false otherwise. |
hashCode
public int hashCode ()
Returns a hash code value for the object. This method is
supported for the benefit of hash tables such as those provided by
HashMap
.
The general contract of hashCode
is:
- 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 inequals
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
method, then calling thehashCode
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
method, then calling thehashCode
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.
Returns | |
---|---|
int |
a hash code value for this object. |
setGravity
public void setGravity (int gravity)
Describes how the child views are positioned. Default is LEFT | BASELINE
.
See Gravity
.
Related XML Attributes:
Parameters | |
---|---|
gravity |
int : the new gravity value |
Protected methods
setBaseAttributes
protected void setBaseAttributes (TypedArray attributes, int widthAttr, int heightAttr)
Extracts the layout parameters from the supplied attributes.
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 |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-04-04 UTC.