Android APIs
public abstract class

OrientationHelper

extends Object
java.lang.Object
   ↳ android.support.v7.widget.OrientationHelper

Class Overview

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.

Summary

Constants
int HORIZONTAL
int VERTICAL
Fields
protected final RecyclerView.LayoutManager mLayoutManager
Public Methods
static OrientationHelper createHorizontalHelper(RecyclerView.LayoutManager layoutManager)
Creates a horizontal OrientationHelper for the given LayoutManager.
static OrientationHelper createOrientationHelper(RecyclerView.LayoutManager layoutManager, int orientation)
Creates an OrientationHelper for the given LayoutManager and orientation.
static OrientationHelper createVerticalHelper(RecyclerView.LayoutManager layoutManager)
Creates a vertical OrientationHelper for the given LayoutManager.
abstract int getDecoratedEnd(View view)
Returns the end of the view including its decoration and margin.
abstract int getDecoratedMeasurement(View view)
Returns the space occupied by this View in the current orientation including decorations and margins.
abstract int getDecoratedMeasurementInOther(View view)
Returns the space occupied by this View in the perpendicular orientation including decorations and margins.
abstract int getDecoratedStart(View view)
Returns the start of the view including its decoration and margin.
abstract int getEnd()
Returns the end position of the layout without taking padding into account.
abstract int getEndAfterPadding()
Returns the end position of the layout after the end padding is removed.
abstract int getEndPadding()
Returns the padding at the end of the layout.
abstract int getStartAfterPadding()
Returns the start position of the layout after the start padding is added.
abstract int getTotalSpace()
Returns the total space to layout.
int getTotalSpaceChange()
Returns the layout space change between the previous layout pass and current layout pass.
abstract void offsetChild(View view, int offset)
Offsets the child in this orientation.
abstract void offsetChildren(int amount)
Offsets all children's positions by the given amount.
void onLayoutComplete()
Call this method after onLayout method is complete if state is NOT pre-layout.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int HORIZONTAL

Constant Value: 0 (0x00000000)

public static final int VERTICAL

Constant Value: 1 (0x00000001)

Fields

protected final RecyclerView.LayoutManager mLayoutManager

Public Methods

public static OrientationHelper createHorizontalHelper (RecyclerView.LayoutManager layoutManager)

Creates a horizontal OrientationHelper for the given LayoutManager.

Parameters
layoutManager The LayoutManager to attach to.
Returns
  • A new OrientationHelper

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

Creates an OrientationHelper for the given LayoutManager and orientation.

Parameters
layoutManager LayoutManager to attach to
orientation Desired orientation. Should be HORIZONTAL or VERTICAL
Returns
  • A new OrientationHelper

public static OrientationHelper createVerticalHelper (RecyclerView.LayoutManager layoutManager)

Creates a vertical OrientationHelper for the given LayoutManager.

Parameters
layoutManager The LayoutManager to attach to.
Returns
  • A new OrientationHelper

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
view The view element to check
Returns
  • The last pixel of the element

public abstract int getDecoratedMeasurement (View view)

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

Parameters
view The view element to check
Returns
  • Total space occupied by this view

public abstract int getDecoratedMeasurementInOther (View view)

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

Parameters
view The view element to check
Returns
  • Total space occupied by this view in the perpendicular orientation to current one

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
view The view element to check
Returns
  • The first pixel of the element

public abstract int getEnd ()

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

Returns
  • The end boundary for this layout without considering padding.

public abstract int getEndAfterPadding ()

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

Returns
  • The end boundary for this layout.

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
  • The padding at the end of the layout.

public abstract int getStartAfterPadding ()

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

Returns
  • The very first pixel we can draw.

public abstract int getTotalSpace ()

Returns the total space to layout. This number is the difference between getEndAfterPadding() and getStartAfterPadding().

Returns
  • Total space to layout children

public int getTotalSpaceChange ()

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

Make sure you call onLayoutComplete() at the end of your LayoutManager's onLayoutChildren(RecyclerView.Recycler, RecyclerView.State) method.

Returns
  • The difference between the current total space and previous layout's total space.

public abstract void offsetChild (View view, int offset)

Offsets the child in this orientation.

Parameters
view View to offset
offset offset amount

public abstract void offsetChildren (int amount)

Offsets all children's positions by the given amount.

Parameters
amount Value to add to each child's layout parameters

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.