# RecyclerView.LayoutParams

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

*** ** * ** ***


```
public class RecyclerView.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.recyclerview.widget.RecyclerView.LayoutParams](https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutParams) |

Known direct subclasses [GridLayoutManager.LayoutParams](https://developer.android.com/reference/androidx/recyclerview/widget/GridLayoutManager.LayoutParams), [StaggeredGridLayoutManager.LayoutParams](https://developer.android.com/reference/androidx/recyclerview/widget/StaggeredGridLayoutManager.LayoutParams)

|---|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/GridLayoutManager.LayoutParams` | LayoutParams used by GridLayoutManager. |
| `https://developer.android.com/reference/androidx/recyclerview/widget/StaggeredGridLayoutManager.LayoutParams` | LayoutParams used by StaggeredGridLayoutManager. |

*** ** * ** ***

`https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html` subclass for children of `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView`. Custom `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutManager` are encouraged to create their own subclass of this `LayoutParams` class to store any additional required per-child view metadata about the layout.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutParams#LayoutParams(androidx.recyclerview.widget.RecyclerView.LayoutParams)(https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutParams source)` |
| `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutParams#LayoutParams(android.view.ViewGroup.LayoutParams)(https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html source)` |
| `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutParams#LayoutParams(android.view.ViewGroup.MarginLayoutParams)(https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html source)` |
| `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutParams#LayoutParams(android.content.Context,android.util.AttributeSet)(https://developer.android.com/reference/android/content/Context.html c, https://developer.android.com/reference/android/util/AttributeSet.html attrs)` |
| `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutParams#LayoutParams(int,int)(int width, int height)` |

| ### Public methods |
|---|---|
| `int` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutParams#getAbsoluteAdapterPosition()()` Returns the up-to-date adapter position that the view this LayoutParams is attached to corresponds to in the `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView`. |
| `int` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutParams#getBindingAdapterPosition()()` Returns the up-to-date adapter position that the view this LayoutParams is attached to corresponds to with respect to the `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.Adapter` that bound this View. |
| `int` | `[getViewAdapterPosition](https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutParams#getViewAdapterPosition())()` **This method is deprecated.** This method is confusing when nested adapters are used. <br /> |
| `int` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutParams#getViewLayoutPosition()()` Returns the adapter position that the view this LayoutParams is attached to corresponds to as of latest layout calculation. |
| `int` | `[getViewPosition](https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutParams#getViewPosition())()` **This method is deprecated.** use `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutParams#getViewLayoutPosition()` or `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutParams#getViewAdapterPosition()` <br /> |
| `boolean` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutParams#isItemChanged()()` Returns true if the adapter data item corresponding to the view this LayoutParams is attached to has been changed in the data set. |
| `boolean` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutParams#isItemRemoved()()` Returns true if the adapter data item corresponding to the view this LayoutParams is attached to has been removed from the data set. |
| `boolean` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutParams#isViewInvalid()()` Returns true if the view this LayoutParams is attached to is now representing potentially invalid data. |
| `boolean` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutParams#viewNeedsUpdate()()` Returns true if the view this LayoutParams is attached to needs to have its content updated from the corresponding adapter. |

| ### 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 constructors

### LayoutParams

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

```
public LayoutParams(RecyclerView.LayoutParams source)
```

### LayoutParams

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

```
public LayoutParams(ViewGroup.LayoutParams source)
```

### LayoutParams

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

```
public LayoutParams(ViewGroup.MarginLayoutParams source)
```

### LayoutParams

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

```
public LayoutParams(Context c, AttributeSet attrs)
```

### LayoutParams

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

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

## Public methods

### getAbsoluteAdapterPosition

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

```
public int getAbsoluteAdapterPosition()
```

Returns the up-to-date adapter position that the view this LayoutParams is attached to corresponds to in the `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView`. If the `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView` has an `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.Adapter` that merges other adapters, this position will be with respect to the adapter that is assigned to the `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView`.

| Returns |
|---|---|
| `int` | the up-to-date adapter position this view with respect to the RecyclerView. It may return `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView#NO_POSITION()` if item represented by this View has been removed or its up-to-date position cannot be calculated. |

### getBindingAdapterPosition

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

```
public int getBindingAdapterPosition()
```

Returns the up-to-date adapter position that the view this LayoutParams is attached to corresponds to with respect to the `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.Adapter` that bound this View.

| Returns |
|---|---|
| `int` | the up-to-date adapter position this view relative to the `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.Adapter` that bound this View. It may return `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView#NO_POSITION()` if item represented by this View has been removed or its up-to-date position cannot be calculated. |

### getViewAdapterPosition

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

```
public int [getViewAdapterPosition](https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutParams#getViewAdapterPosition())()
```

> [!CAUTION]
> **This method is deprecated.**   
>
> This method is confusing when nested adapters are used. If you are calling from the context of an `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.Adapter`, use `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutParams#getBindingAdapterPosition()`. If you need the position that `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView` sees, use `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutParams#getAbsoluteAdapterPosition()`.

### getViewLayoutPosition

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

```
public int getViewLayoutPosition()
```

Returns the adapter position that the view this LayoutParams is attached to corresponds to as of latest layout calculation.

| Returns |
|---|---|
| `int` | the adapter position this view as of latest layout pass |

### getViewPosition

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

```
public int [getViewPosition](https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutParams#getViewPosition())()
```

> [!CAUTION]
> **This method is deprecated.**   
>
> use `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutParams#getViewLayoutPosition()` or `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutParams#getViewAdapterPosition()`

### isItemChanged

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

```
public boolean isItemChanged()
```

Returns true if the adapter data item corresponding to the view this LayoutParams is attached to has been changed in the data set. A LayoutManager may choose to treat it differently in order to animate its changing state.

| Returns |
|---|---|
| `boolean` | true if the item the view corresponds to was changed in the data set |

### isItemRemoved

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

```
public boolean isItemRemoved()
```

Returns true if the adapter data item corresponding to the view this LayoutParams is attached to has been removed from the data set. A LayoutManager may choose to treat it differently in order to animate its outgoing or disappearing state.

| Returns |
|---|---|
| `boolean` | true if the item the view corresponds to was removed from the data set |

### isViewInvalid

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

```
public boolean isViewInvalid()
```

Returns true if the view this LayoutParams is attached to is now representing potentially invalid data. A LayoutManager should scrap/recycle it.

| Returns |
|---|---|
| `boolean` | true if the view is invalid |

### viewNeedsUpdate

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

```
public boolean viewNeedsUpdate()
```

Returns true if the view this LayoutParams is attached to needs to have its content updated from the corresponding adapter.

| Returns |
|---|---|
| `boolean` | true if the view should have its content updated |