# OrientationHelper

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

*** ** * ** ***


```
public abstract class OrientationHelper
```

<br />

*** ** * ** ***

Helper class for LayoutManagers to abstract measurements depending on the View's orientation.

It is developed to easily support vertical and horizontal orientations in a LayoutManager but can also be used to abstract calls around view bounds and child measurements with margins and decorations.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#createHorizontalHelper(androidx.recyclerview.widget.RecyclerView.LayoutManager)` |   |
| `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#createVerticalHelper(androidx.recyclerview.widget.RecyclerView.LayoutManager)` |   |

## Summary

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#HORIZONTAL() = 0` |
| `static final int` | `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#VERTICAL() = 1` |

| ### Protected fields |
|---|---|
| `final https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutManager` | `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#mLayoutManager()` |

| ### Public methods |
|---|---|
| `static https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper` | `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#createHorizontalHelper(androidx.recyclerview.widget.RecyclerView.LayoutManager)(https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutManager layoutManager)` Creates a horizontal OrientationHelper for the given LayoutManager. |
| `static https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper` | `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#createOrientationHelper(androidx.recyclerview.widget.RecyclerView.LayoutManager,int)( https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutManager layoutManager, int orientation )` Creates an OrientationHelper for the given LayoutManager and orientation. |
| `static https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper` | `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#createVerticalHelper(androidx.recyclerview.widget.RecyclerView.LayoutManager)(https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutManager layoutManager)` Creates a vertical OrientationHelper for the given LayoutManager. |
| `abstract int` | `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#getDecoratedEnd(android.view.View)(https://developer.android.com/reference/android/view/View.html view)` Returns the end of the view including its decoration and margin. |
| `abstract int` | `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#getDecoratedMeasurement(android.view.View)(https://developer.android.com/reference/android/view/View.html view)` Returns the space occupied by this View in the current orientation including decorations and margins. |
| `abstract int` | `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#getDecoratedMeasurementInOther(android.view.View)(https://developer.android.com/reference/android/view/View.html view)` Returns the space occupied by this View in the perpendicular orientation including decorations and margins. |
| `abstract int` | `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#getDecoratedStart(android.view.View)(https://developer.android.com/reference/android/view/View.html view)` Returns the start of the view including its decoration and margin. |
| `abstract int` | `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#getEnd()()` Returns the end position of the layout without taking padding into account. |
| `abstract int` | `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#getEndAfterPadding()()` Returns the end position of the layout after the end padding is removed. |
| `abstract int` | `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#getEndPadding()()` Returns the padding at the end of the layout. |
| `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutManager` | `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#getLayoutManager()()` Returns the `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutManager` that is associated with this OrientationHelper. |
| `abstract int` | `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#getMode()()` Returns the MeasureSpec mode for the current orientation from the LayoutManager. |
| `abstract int` | `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#getModeInOther()()` Returns the MeasureSpec mode for the perpendicular orientation from the LayoutManager. |
| `abstract int` | `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#getStartAfterPadding()()` Returns the start position of the layout after the start padding is added. |
| `abstract int` | `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#getTotalSpace()()` Returns the total space to layout. |
| `int` | `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#getTotalSpaceChange()()` Returns the layout space change between the previous layout pass and current layout pass. |
| `abstract int` | `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#getTransformedEndWithDecoration(android.view.View)(https://developer.android.com/reference/android/view/View.html view)` Returns the end of the View after its matrix transformations are applied to its layout position. |
| `abstract int` | `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#getTransformedStartWithDecoration(android.view.View)(https://developer.android.com/reference/android/view/View.html view)` Returns the start of the View after its matrix transformations are applied to its layout position. |
| `abstract void` | `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#offsetChild(android.view.View,int)(https://developer.android.com/reference/android/view/View.html view, int offset)` Offsets the child in this orientation. |
| `abstract void` | `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#offsetChildren(int)(int amount)` Offsets all children's positions by the given amount. |
| `void` | `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#onLayoutComplete()()` Call this method after onLayout method is complete if state is NOT pre-layout. |

## Constants

### HORIZONTAL

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

```
public static final int HORIZONTAL = 0
```

### VERTICAL

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

```
public static final int VERTICAL = 1
```

## Protected fields

### mLayoutManager

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

```
protected final RecyclerView.LayoutManager mLayoutManager
```

## Public methods

### createHorizontalHelper

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

```
public static OrientationHelper createHorizontalHelper(RecyclerView.LayoutManager layoutManager)
```

Creates a horizontal OrientationHelper for the given LayoutManager.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutManager layoutManager` | The LayoutManager to attach to. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper` | A new OrientationHelper |

### createOrientationHelper

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

```
public static OrientationHelper createOrientationHelper(
    RecyclerView.LayoutManager layoutManager,
    int orientation
)
```

Creates an OrientationHelper for the given LayoutManager and orientation.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutManager layoutManager` | LayoutManager to attach to |
| `int orientation` | Desired orientation. Should be `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#HORIZONTAL()` or `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#VERTICAL()` |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper` | A new OrientationHelper |

### createVerticalHelper

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

```
public static OrientationHelper createVerticalHelper(RecyclerView.LayoutManager layoutManager)
```

Creates a vertical OrientationHelper for the given LayoutManager.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutManager layoutManager` | The LayoutManager to attach to. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper` | A new OrientationHelper |

### getDecoratedEnd

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

```
public abstract int getDecoratedEnd(View view)
```

Returns the end of the view including its decoration and margin.

For example, for the horizontal helper, if a View's right is at pixel 200, has 2px right decoration and 3px right margin, returned value will be 205.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/view/View.html view` | The view element to check |

| Returns |
|---|---|
| `int` | The last pixel of the element |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#getDecoratedStart(android.view.View)` |   |

### getDecoratedMeasurement

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

```
public abstract int getDecoratedMeasurement(View view)
```

Returns the space occupied by this View in the current orientation including decorations and margins.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/view/View.html view` | The view element to check |

| Returns |
|---|---|
| `int` | Total space occupied by this view |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#getDecoratedMeasurementInOther(android.view.View)` |   |

### getDecoratedMeasurementInOther

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

```
public abstract int getDecoratedMeasurementInOther(View view)
```

Returns the space occupied by this View in the perpendicular orientation including decorations and margins.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/view/View.html view` | The view element to check |

| Returns |
|---|---|
| `int` | Total space occupied by this view in the perpendicular orientation to current one |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#getDecoratedMeasurement(android.view.View)` |   |

### getDecoratedStart

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

```
public abstract int getDecoratedStart(View view)
```

Returns the start of the view including its decoration and margin.

For example, for the horizontal helper, if a View's left is at pixel 20, has 2px left decoration and 3px left margin, returned value will be 15px.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/view/View.html view` | The view element to check |

| Returns |
|---|---|
| `int` | The first pixel of the element |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#getDecoratedEnd(android.view.View)` |   |

### getEnd

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

```
public abstract int getEnd()
```

Returns the end position of the layout without taking padding into account.

| Returns |
|---|---|
| `int` | The end boundary for this layout without considering padding. |

### getEndAfterPadding

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

```
public abstract int getEndAfterPadding()
```

Returns the end position of the layout after the end padding is removed.

| Returns |
|---|---|
| `int` | The end boundary for this layout. |

### getEndPadding

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

```
public abstract int getEndPadding()
```

Returns the padding at the end of the layout. For horizontal helper, this is the right padding and for vertical helper, this is the bottom padding. This method does not check whether the layout is RTL or not.

| Returns |
|---|---|
| `int` | The padding at the end of the layout. |

### getLayoutManager

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

```
public RecyclerView.LayoutManager getLayoutManager()
```

Returns the `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutManager` that is associated with this OrientationHelper.

### getMode

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

```
public abstract int getMode()
```

Returns the MeasureSpec mode for the current orientation from the LayoutManager.

| Returns |
|---|---|
| `int` | The current measure spec mode. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/view/View.MeasureSpec.html` |   |
| `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutManager#getWidthMode()` |   |
| `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutManager#getHeightMode()` |   |

### getModeInOther

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

```
public abstract int getModeInOther()
```

Returns the MeasureSpec mode for the perpendicular orientation from the LayoutManager.

| Returns |
|---|---|
| `int` | The current measure spec mode. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/view/View.MeasureSpec.html` |   |
| `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutManager#getWidthMode()` |   |
| `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutManager#getHeightMode()` |   |

### getStartAfterPadding

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

```
public abstract int getStartAfterPadding()
```

Returns the start position of the layout after the start padding is added.

| Returns |
|---|---|
| `int` | The very first pixel we can draw. |

### getTotalSpace

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

```
public abstract int getTotalSpace()
```

Returns the total space to layout. This number is the difference between `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#getEndAfterPadding()` and `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#getStartAfterPadding()`.

| Returns |
|---|---|
| `int` | Total space to layout children |

### getTotalSpaceChange

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

```
public int getTotalSpaceChange()
```

Returns the layout space change between the previous layout pass and current layout pass.

Make sure you call `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#onLayoutComplete()` at the end of your LayoutManager's `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutManager#onLayoutChildren(androidx.recyclerview.widget.RecyclerView.Recycler,androidx.recyclerview.widget.RecyclerView.State)` method.

| Returns |
|---|---|
| `int` | The difference between the current total space and previous layout's total space. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/OrientationHelper#onLayoutComplete()` |   |

### getTransformedEndWithDecoration

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

```
public abstract int getTransformedEndWithDecoration(View view)
```

Returns the end of the View after its matrix transformations are applied to its layout position.

This method is useful when trying to detect the visible edge of a View.

It includes the decorations but does not include the margins.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/view/View.html view` | The view whose transformed end will be returned |

| Returns |
|---|---|
| `int` | The end of the View after its decor insets and transformation matrix is applied to its position |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutManager#getTransformedBoundingBox(android.view.View,boolean,android.graphics.Rect)` |   |

### getTransformedStartWithDecoration

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

```
public abstract int getTransformedStartWithDecoration(View view)
```

Returns the start of the View after its matrix transformations are applied to its layout position.

This method is useful when trying to detect the visible edge of a View.

It includes the decorations but does not include the margins.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/view/View.html view` | The view whose transformed start will be returned |

| Returns |
|---|---|
| `int` | The start of the View after its decor insets and transformation matrix is applied to its position |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.LayoutManager#getTransformedBoundingBox(android.view.View,boolean,android.graphics.Rect)` |   |

### offsetChild

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

```
public abstract void offsetChild(View view, int offset)
```

Offsets the child in this orientation.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/view/View.html view` | View to offset |
| `int offset` | offset amount |

### offsetChildren

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

```
public abstract void offsetChildren(int amount)
```

Offsets all children's positions by the given amount.

| Parameters |
|---|---|
| `int amount` | Value to add to each child's layout parameters |

### onLayoutComplete

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

```
public void onLayoutComplete()
```

Call this method after onLayout method is complete if state is NOT pre-layout. This method records information like layout bounds that might be useful in the next layout calculations.