# CoordinatorLayout.LayoutParams

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

*** ** * ** ***


```
public class CoordinatorLayout.LayoutParams extends ViewGroup.MarginLayoutParams
```

<br />

|---|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.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.coordinatorlayout.widget.CoordinatorLayout.LayoutParams](https://developer.android.com/reference/androidx/coordinatorlayout/widget/CoordinatorLayout.LayoutParams) |

*** ** * ** ***

Parameters describing the desired layout for a child of a `https://developer.android.com/reference/androidx/coordinatorlayout/widget/CoordinatorLayout`.

## Summary

| ### Public fields |
|---|---|
| `int` | `https://developer.android.com/reference/androidx/coordinatorlayout/widget/CoordinatorLayout.LayoutParams#anchorGravity()` A `https://developer.android.com/reference/android/view/Gravity.html` value describing which edge of a child view's `https://developer.android.com/reference/androidx/coordinatorlayout/widget/CoordinatorLayout.LayoutParams#getAnchorId()` view the child should position itself relative to. |
| `int` | `https://developer.android.com/reference/androidx/coordinatorlayout/widget/CoordinatorLayout.LayoutParams#dodgeInsetEdges()` A `https://developer.android.com/reference/android/view/Gravity.html` value describing how this child view dodges any inset child views in the CoordinatorLayout. |
| `int` | `https://developer.android.com/reference/androidx/coordinatorlayout/widget/CoordinatorLayout.LayoutParams#gravity()` A `https://developer.android.com/reference/android/view/Gravity.html` value describing how this child view should lay out. |
| `int` | `https://developer.android.com/reference/androidx/coordinatorlayout/widget/CoordinatorLayout.LayoutParams#insetEdge()` A `https://developer.android.com/reference/android/view/Gravity.html` value describing how this child view insets the CoordinatorLayout. |
| `int` | `https://developer.android.com/reference/androidx/coordinatorlayout/widget/CoordinatorLayout.LayoutParams#keyline()` The index of the horizontal keyline specified to the parent CoordinatorLayout that this child should align relative to. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/coordinatorlayout/widget/CoordinatorLayout.LayoutParams#LayoutParams(androidx.coordinatorlayout.widget.CoordinatorLayout.LayoutParams)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/coordinatorlayout/widget/CoordinatorLayout.LayoutParams p)` |
| `https://developer.android.com/reference/androidx/coordinatorlayout/widget/CoordinatorLayout.LayoutParams#LayoutParams(android.view.ViewGroup.LayoutParams)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html p)` |
| `https://developer.android.com/reference/androidx/coordinatorlayout/widget/CoordinatorLayout.LayoutParams#LayoutParams(android.view.ViewGroup.MarginLayoutParams)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html p)` |
| `https://developer.android.com/reference/androidx/coordinatorlayout/widget/CoordinatorLayout.LayoutParams#LayoutParams(int,int)(int width, int height)` |

| ### Public methods |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IdRes int` | `https://developer.android.com/reference/androidx/coordinatorlayout/widget/CoordinatorLayout.LayoutParams#getAnchorId()()` Get the id of this view's anchor. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/coordinatorlayout/widget/CoordinatorLayout.Behavior` | `https://developer.android.com/reference/androidx/coordinatorlayout/widget/CoordinatorLayout.LayoutParams#getBehavior()()` Get the behavior governing the layout and interaction of the child view within a parent CoordinatorLayout. |
| `void` | `https://developer.android.com/reference/androidx/coordinatorlayout/widget/CoordinatorLayout.LayoutParams#setAnchorId(int)(@https://developer.android.com/reference/androidx/annotation/IdRes int id)` Set the id of this view's anchor. |
| `void` | `https://developer.android.com/reference/androidx/coordinatorlayout/widget/CoordinatorLayout.LayoutParams#setBehavior(androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/coordinatorlayout/widget/CoordinatorLayout.Behavior behavior)` Set the behavior governing the layout and interaction of the child view within a parent CoordinatorLayout. |

| ### Inherited Constants |
|---|
| From [android.view.ViewGroup.LayoutParams](https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html) |---|---| | `static final int` | `https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#FILL_PARENT = -1` **This field is deprecated.** | | `static final int` | `https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#MATCH_PARENT = -1` | | `static final int` | `https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#WRAP_CONTENT = -2` | |

| ### Inherited fields |
|---|
| From [android.view.ViewGroup.LayoutParams](https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html) |---|---| | `int` | `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` | | `int` | `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) |---|---| | `int` | `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#bottomMargin` | | `int` | `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#leftMargin` | | `int` | `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#rightMargin` | | `int` | `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#topMargin` | |

| ### Inherited methods |
|---|
| From [android.view.ViewGroup.LayoutParams](https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html) |---|---| | `void` | `https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#setBaseAttributes(android.content.res.TypedArray, int, int)(https://developer.android.com/reference/android/content/res/TypedArray.html a, int widthAttr, int heightAttr)` | |
| From [android.view.ViewGroup.MarginLayoutParams](https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html) |---|---| | `int` | `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#getLayoutDirection()()` | | `int` | `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#getMarginEnd()()` | | `int` | `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#getMarginStart()()` | | `boolean` | `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#isMarginRelative()()` | | `void` | `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#resolveLayoutDirection(int)(int layoutDirection)` | | `void` | `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#setLayoutDirection(int)(int layoutDirection)` | | `void` | `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#setMarginEnd(int)(int end)` | | `void` | `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#setMarginStart(int)(int start)` | | `void` | `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#setMargins(int, int, int, int)(int left, int top, int right, int bottom)` | |

## Public fields

### anchorGravity

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

```
public int anchorGravity
```

A `https://developer.android.com/reference/android/view/Gravity.html` value describing which edge of a child view's `https://developer.android.com/reference/androidx/coordinatorlayout/widget/CoordinatorLayout.LayoutParams#getAnchorId()` view the child should position itself relative to.

### dodgeInsetEdges

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

```
public int dodgeInsetEdges
```

A `https://developer.android.com/reference/android/view/Gravity.html` value describing how this child view dodges any inset child views in the CoordinatorLayout. Any views which are inset on the same edge as this view is set to dodge will result in this view being moved so that the views do not overlap.

### gravity

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

```
public int gravity
```

A `https://developer.android.com/reference/android/view/Gravity.html` value describing how this child view should lay out. If either or both of the axes are not specified, they are treated by CoordinatorLayout as `https://developer.android.com/reference/android/view/Gravity.html#TOP` or `https://developer.android.com/reference/androidx/core/view/GravityCompat#START()`. If an `https://developer.android.com/reference/androidx/coordinatorlayout/widget/CoordinatorLayout.LayoutParams#setAnchorId(int)` is also specified, the gravity describes how this child view should be positioned relative to its anchored position.

### insetEdge

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

```
public int insetEdge
```

A `https://developer.android.com/reference/android/view/Gravity.html` value describing how this child view insets the CoordinatorLayout. Other child views which are set to dodge the same inset edges will be moved appropriately so that the views do not overlap.

### keyline

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

```
public int keyline
```

The index of the horizontal keyline specified to the parent CoordinatorLayout that this child should align relative to. If an `https://developer.android.com/reference/androidx/coordinatorlayout/widget/CoordinatorLayout.LayoutParams#setAnchorId(int)` is present the keyline will be ignored.

## Public constructors

### LayoutParams

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

```
public LayoutParams(@NonNull CoordinatorLayout.LayoutParams p)
```

### LayoutParams

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

```
public LayoutParams(@NonNull ViewGroup.LayoutParams p)
```

### LayoutParams

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

```
public LayoutParams(@NonNull ViewGroup.MarginLayoutParams p)
```

### LayoutParams

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

```
public LayoutParams(int width, int height)
```

## Public methods

### getAnchorId

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

```
public @IdRes int getAnchorId()
```

Get the id of this view's anchor.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IdRes int` | A `https://developer.android.com/reference/android/view/View.html#getId()` or `https://developer.android.com/reference/android/view/View.html#NO_ID` if there is no anchor |

### getBehavior

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

```
public @Nullable CoordinatorLayout.Behavior getBehavior()
```

Get the behavior governing the layout and interaction of the child view within a parent CoordinatorLayout.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/coordinatorlayout/widget/CoordinatorLayout.Behavior` | The current behavior or null if no behavior is specified |

### setAnchorId

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

```
public void setAnchorId(@IdRes int id)
```

Set the id of this view's anchor.

The view with this id must be a descendant of the CoordinatorLayout containing the child view this LayoutParams belongs to. It may not be the child view with this LayoutParams or a descendant of it.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IdRes int id` | The `https://developer.android.com/reference/android/view/View.html#getId()` of the anchor or `https://developer.android.com/reference/android/view/View.html#NO_ID` if there is no anchor |

### setBehavior

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

```
public void setBehavior(@Nullable CoordinatorLayout.Behavior behavior)
```

Set the behavior governing the layout and interaction of the child view within a parent CoordinatorLayout.

Setting a new behavior will remove any currently associated `https://developer.android.com/reference/androidx/coordinatorlayout/widget/CoordinatorLayout.Behavior#setTag(android.view.View,java.lang.Object)`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/coordinatorlayout/widget/CoordinatorLayout.Behavior behavior` | The behavior to set or null for no special behavior |