# GridLayout.LayoutParams

Artifact: [androidx.gridlayout:gridlayout](https://developer.android.com/jetpack/androidx/releases/gridlayout) [View Source](https://cs.android.com/search?q=file:androidx/gridlayout/widget/GridLayout.java+class:androidx.gridlayout.widget.GridLayout.LayoutParams) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/gridlayout#1.0.0)

*** ** * ** ***

Kotlin \|[Java](https://developer.android.com/reference/androidx/gridlayout/widget/GridLayout.LayoutParams "View this page in Java")


```
class GridLayout.LayoutParams : ViewGroup.MarginLayoutParams
```

<br />

|---|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) ||||
| ↳ | [android.view.ViewGroup.LayoutParams](https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html) |||
|   | ↳ | [android.view.ViewGroup.MarginLayoutParams](https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html) ||
|   |   | ↳ | [androidx.gridlayout.widget.GridLayout.LayoutParams](https://developer.android.com/reference/kotlin/androidx/gridlayout/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 `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.LayoutParams#rowSpec()` and `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.LayoutParams#columnSpec()` layout parameters. `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.Spec` 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 `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/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 the `https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#width` and `https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#height` properties are both `https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#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 `https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#MATCH_PARENT` from `https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#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 `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/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

- `https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#width` = `https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#WRAP_CONTENT`
- `https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#height` = `https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#WRAP_CONTENT`
- `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#topMargin` = 0 when `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout#setUseDefaultMargins(boolean)` is `false`; otherwise `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout#UNDEFINED()`, to indicate that a default value should be computed on demand.
- `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#leftMargin` = 0 when `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout#setUseDefaultMargins(boolean)` is `false`; otherwise `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout#UNDEFINED()`, to indicate that a default value should be computed on demand.
- `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#bottomMargin` = 0 when `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout#setUseDefaultMargins(boolean)` is `false`; otherwise `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout#UNDEFINED()`, to indicate that a default value should be computed on demand.
- `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#rightMargin` = 0 when `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout#setUseDefaultMargins(boolean)` is `false`; otherwise `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout#UNDEFINED()`, to indicate that a default value should be computed on demand.
- `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.LayoutParams#rowSpec()``.row` = `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout#UNDEFINED()`
- `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.LayoutParams#rowSpec()``.rowSpan` = 1
- `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.LayoutParams#rowSpec()``.alignment` = `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout#BASELINE()`
- `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.LayoutParams#rowSpec()``.weight` = 0
- `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.LayoutParams#columnSpec()``.column` = `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout#UNDEFINED()`
- `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.LayoutParams#columnSpec()``.columnSpan` = 1
- `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.LayoutParams#columnSpec()``.alignment` = `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout#START()`
- `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.LayoutParams#columnSpec()``.weight` = 0

See `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout` for a more complete description of the conventions used by GridLayout in the interpretation of the properties of this class.

name android:row

name android:rowSpan

name android:rowWeight

name android:column

name android:columnSpan

name android:columnWeight

name android:gravity

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.LayoutParams#LayoutParams()()` Constructs a new LayoutParams with default values as defined in `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.LayoutParams`. |
| `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.LayoutParams#LayoutParams(android.view.ViewGroup.LayoutParams)(params: https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html!)` |
| `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.LayoutParams#LayoutParams(android.view.ViewGroup.MarginLayoutParams)(params: https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html!)` |
| `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.LayoutParams#LayoutParams(androidx.gridlayout.widget.GridLayout.LayoutParams)(source: https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.LayoutParams!)` Copy constructor. |
| `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.LayoutParams#LayoutParams(android.content.Context,android.util.AttributeSet)(context: https://developer.android.com/reference/android/content/Context.html!, attrs: https://developer.android.com/reference/android/util/AttributeSet.html!)` Values not defined in the attribute set take the default values defined in `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.LayoutParams`. |
| `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.LayoutParams#LayoutParams(androidx.gridlayout.widget.GridLayout.Spec,androidx.gridlayout.widget.GridLayout.Spec)(rowSpec: https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.Spec!, columnSpec: https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.Spec!)` Constructs a new LayoutParams instance for this `rowSpec` and `columnSpec`. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.LayoutParams#equals(java.lang.Object)(o: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html!)` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.LayoutParams#hashCode()()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.LayoutParams#setGravity(int)(gravity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Describes how the child views are positioned. |

| ### Protected functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.LayoutParams#setBaseAttributes(android.content.res.TypedArray,int,int)(attributes: https://developer.android.com/reference/android/content/res/TypedArray.html!, widthAttr: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, heightAttr: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` |

| ### Public properties |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.Spec!` | `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.LayoutParams#columnSpec()` The spec that defines the horizontal characteristics of the cell group described by these layout parameters. |
| `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.Spec!` | `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.LayoutParams#rowSpec()` The spec that defines the vertical characteristics of the cell group described by these layout parameters. |

| ### Inherited Constants |
|---|
| From [android.view.ViewGroup.LayoutParams](https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html) |---|---| | `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#FILL_PARENT = -1` **This property is deprecated.** | | `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#MATCH_PARENT = -1` | | `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#WRAP_CONTENT = -2` | |

| ### Inherited functions |
|---|
| From [android.view.ViewGroup.MarginLayoutParams](https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html) |---|---| | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#getLayoutDirection()()` | | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#getMarginEnd()()` | | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#getMarginStart()()` | | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#isMarginRelative()()` | | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#resolveLayoutDirection(int)(layoutDirection: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` | | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#setLayoutDirection(int)(layoutDirection: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` | | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#setMarginEnd(int)(end: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` | | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#setMarginStart(int)(start: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` | | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#setMargins(int, int, int, int)(left: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, top: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, right: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, bottom: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` | |

| ### Inherited properties |
|---|
| From [android.view.ViewGroup.LayoutParams](https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html) |---|---| | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#height` | | `https://developer.android.com/reference/android/view/animation/LayoutAnimationController.AnimationParameters.html!` | `https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#layoutAnimationParameters` | | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#width` | |
| From [android.view.ViewGroup.MarginLayoutParams](https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html) |---|---| | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#bottomMargin` | | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#leftMargin` | | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#rightMargin` | | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#topMargin` | |

## Public constructors

### LayoutParams

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/gridlayout#1.0.0)

```
LayoutParams()
```

Constructs a new LayoutParams with default values as defined in `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.LayoutParams`.

### LayoutParams

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/gridlayout#1.0.0)

```
LayoutParams(params: ViewGroup.LayoutParams!)
```

### LayoutParams

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/gridlayout#1.0.0)

```
LayoutParams(params: ViewGroup.MarginLayoutParams!)
```

### LayoutParams

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/gridlayout#1.0.0)

```
LayoutParams(source: GridLayout.LayoutParams!)
```

Copy constructor. Clones the width, height, margin values, row spec, and column spec of the source.

| Parameters |
|---|---|
| `source: https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.LayoutParams!` | The layout params to copy from. |

### LayoutParams

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/gridlayout#1.0.0)

```
LayoutParams(context: Context!, attrs: AttributeSet!)
```

Values not defined in the attribute set take the default values defined in `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.LayoutParams`.

### LayoutParams

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/gridlayout#1.0.0)

```
LayoutParams(rowSpec: GridLayout.Spec!, columnSpec: GridLayout.Spec!)
```

Constructs a new LayoutParams instance for this `rowSpec` and `columnSpec`. All other fields are initialized with default values as defined in `https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.LayoutParams`.

| Parameters |
|---|---|
| `rowSpec: https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.Spec!` | the rowSpec |
| `columnSpec: https://developer.android.com/reference/kotlin/androidx/gridlayout/widget/GridLayout.Spec!` | the columnSpec |

## Public functions

### equals

```
fun equals(o: Any!): Boolean
```

### hashCode

```
fun hashCode(): Int
```

### setGravity

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/gridlayout#1.0.0)

```
fun setGravity(gravity: Int): Unit
```

Describes how the child views are positioned. Default is `LEFT | BASELINE`. See `https://developer.android.com/reference/android/view/Gravity.html`.

name android:gravity

| Parameters |
|---|---|
| `gravity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the new gravity value |

## Protected functions

### setBaseAttributes

```
protected fun setBaseAttributes(attributes: TypedArray!, widthAttr: Int, heightAttr: Int): Unit
```

## Public properties

### columnSpec

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/gridlayout#1.0.0)

```
val columnSpec: GridLayout.Spec!
```

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 `https://developer.android.com/reference/android/view/View.html#setLayoutParams(android.view.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 [1.0.0](https://developer.android.com/jetpack/androidx/releases/gridlayout#1.0.0)

```
val rowSpec: GridLayout.Spec!
```

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 `https://developer.android.com/reference/android/view/View.html#setLayoutParams(android.view.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.