Skip to content

Most visited

Recently visited

navigation
added in version 22.1.0
belongs to Maven artifact com.android.support:recyclerview-v7:27.0.0

OrientationHelper

public abstract class OrientationHelper
extends Object

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


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:

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 getMode()

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

abstract int getModeInOther()

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

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 int getTransformedEndWithDecoration(View view)

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

abstract int getTransformedStartWithDecoration(View view)

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

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.

Inherited methods

From class java.lang.Object

Constants

HORIZONTAL

added in version 22.1.0
int HORIZONTAL

Constant Value: 0 (0x00000000)

VERTICAL

added in version 22.1.0
int VERTICAL

Constant Value: 1 (0x00000001)

Fields

mLayoutManager

added in version 22.1.0
RecyclerView.LayoutManager mLayoutManager

Public methods

createHorizontalHelper

added in version 22.1.0
OrientationHelper createHorizontalHelper (RecyclerView.LayoutManager layoutManager)

Creates a horizontal OrientationHelper for the given LayoutManager.

Parameters
layoutManager RecyclerView.LayoutManager: The LayoutManager to attach to.

Returns
OrientationHelper A new OrientationHelper

createOrientationHelper

added in version 22.1.0
OrientationHelper createOrientationHelper (RecyclerView.LayoutManager layoutManager, 
                int orientation)

Creates an OrientationHelper for the given LayoutManager and orientation.

Parameters
layoutManager RecyclerView.LayoutManager: LayoutManager to attach to

orientation int: Desired orientation. Should be HORIZONTAL or VERTICAL

Returns
OrientationHelper A new OrientationHelper

createVerticalHelper

added in version 22.1.0
OrientationHelper createVerticalHelper (RecyclerView.LayoutManager layoutManager)

Creates a vertical OrientationHelper for the given LayoutManager.

Parameters
layoutManager RecyclerView.LayoutManager: The LayoutManager to attach to.

Returns
OrientationHelper A new OrientationHelper

getDecoratedEnd

added in version 22.1.0
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 View: The view element to check

Returns
int The last pixel of the element

See also:

getDecoratedMeasurement

added in version 22.1.0
int getDecoratedMeasurement (View view)

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

Parameters
view View: The view element to check

Returns
int Total space occupied by this view

See also:

getDecoratedMeasurementInOther

added in version 22.1.0
int getDecoratedMeasurementInOther (View view)

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

Parameters
view View: The view element to check

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

See also:

getDecoratedStart

added in version 22.1.0
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 View: The view element to check

Returns
int The first pixel of the element

See also:

getEnd

added in version 22.1.0
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 version 22.1.0
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 version 22.1.0
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.

getMode

added in version 24.1.0
int getMode ()

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

Returns
int The current measure spec mode.

See also:

getModeInOther

added in version 24.1.0
int getModeInOther ()

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

Returns
int The current measure spec mode.

See also:

getStartAfterPadding

added in version 22.1.0
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 version 22.1.0
int getTotalSpace ()

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

Returns
int Total space to layout children

getTotalSpaceChange

added in version 22.1.0
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
int The difference between the current total space and previous layout's total space.

See also:

getTransformedEndWithDecoration

added in version 24.1.0
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
view 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:

getTransformedStartWithDecoration

added in version 24.1.0
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
view 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:

offsetChild

added in version 22.1.0
void offsetChild (View view, 
                int offset)

Offsets the child in this orientation.

Parameters
view View: View to offset

offset int: offset amount

offsetChildren

added in version 22.1.0
void offsetChildren (int amount)

Offsets all children's positions by the given amount.

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

onLayoutComplete

added in version 22.1.0
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.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)