Skip to content

Most visited

Recently visited

navigation
added in version 25.1.0
belongs to Maven artifact com.android.support:gridlayout-v7:27.0.0

GridLayout.LayoutParams

public static class GridLayout.LayoutParams
extends ViewGroup.MarginLayoutParams

java.lang.Object
   ↳ android.view.ViewGroup.LayoutParams
     ↳ android.view.ViewGroup.MarginLayoutParams
       ↳ android.support.v7.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 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 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

Inherited constants

From class android.view.ViewGroup.LayoutParams

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

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

Public constructors

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

Constructs a new LayoutParams instance for this rowSpec and columnSpec.

GridLayout.LayoutParams()

Constructs a new LayoutParams with default values as defined in GridLayout.LayoutParams.

GridLayout.LayoutParams(ViewGroup.LayoutParams params)

GridLayout.LayoutParams(ViewGroup.MarginLayoutParams params)

GridLayout.LayoutParams(GridLayout.LayoutParams source)

Copy constructor.

GridLayout.LayoutParams(Context context, AttributeSet attrs)

Values not defined in the attribute set take the default values defined in GridLayout.LayoutParams.

Public methods

boolean equals(Object o)
int hashCode()
void setGravity(int gravity)

Describes how the child views are positioned.

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

Fields

columnSpec

added in version 25.1.0
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 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

added in version 25.1.0
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 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

GridLayout.LayoutParams

added in version 25.1.0
GridLayout.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 GridLayout.LayoutParams.

Parameters
rowSpec GridLayout.Spec: the rowSpec

columnSpec GridLayout.Spec: the columnSpec

GridLayout.LayoutParams

added in version 25.1.0
GridLayout.LayoutParams ()

Constructs a new LayoutParams with default values as defined in GridLayout.LayoutParams.

GridLayout.LayoutParams

added in version 25.1.0
GridLayout.LayoutParams (ViewGroup.LayoutParams params)

Parameters
params ViewGroup.LayoutParams

GridLayout.LayoutParams

added in version 25.1.0
GridLayout.LayoutParams (ViewGroup.MarginLayoutParams params)

Parameters
params ViewGroup.MarginLayoutParams

GridLayout.LayoutParams

added in version 25.1.0
GridLayout.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.

GridLayout.LayoutParams

added in version 25.1.0
GridLayout.LayoutParams (Context context, 
                AttributeSet attrs)

Values not defined in the attribute set take the default values defined in GridLayout.LayoutParams.

Parameters
context Context

attrs AttributeSet

Public methods

equals

boolean equals (Object o)

Parameters
o Object

Returns
boolean

hashCode

int hashCode ()

Returns
int

setGravity

added in version 25.1.0
void setGravity (int gravity)

Describes how the child views are positioned. Default is LEFT | BASELINE. See Gravity.

Parameters
gravity int: the new gravity value

Protected methods

setBaseAttributes

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

Parameters
attributes TypedArray

widthAttr int

heightAttr int

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)