OrientationHelper


abstract class 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.

Summary

Constants

const Int
const Int

Public functions

java-static OrientationHelper!

Creates a horizontal OrientationHelper for the given LayoutManager.

java-static OrientationHelper!
createOrientationHelper(
    layoutManager: RecyclerView.LayoutManager!,
    orientation: Int
)

Creates an OrientationHelper for the given LayoutManager and orientation.

java-static OrientationHelper!

Creates a vertical OrientationHelper for the given LayoutManager.

abstract Int

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

abstract Int

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

abstract Int

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

abstract Int

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

abstract Int

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

abstract Int

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

abstract Int

Returns the padding at the end of the layout.

RecyclerView.LayoutManager!

Returns the LayoutManager that is associated with this OrientationHelper.

abstract Int

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

abstract Int

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

abstract Int

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

abstract Int

Returns the total space to layout.

Int

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

abstract Int

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

abstract Int

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

abstract Unit
offsetChild(view: View!, offset: Int)

Offsets the child in this orientation.

abstract Unit

Offsets all children's positions by the given amount.

Unit

Call this method after onLayout method is complete if state is NOT pre-layout.

Constants

HORIZONTAL

Added in 1.0.0
const val HORIZONTAL = 0: Int

VERTICAL

Added in 1.0.0
const val VERTICAL = 1: Int

Public functions

createHorizontalHelper

Added in 1.0.0
java-static fun createHorizontalHelper(layoutManager: RecyclerView.LayoutManager!): OrientationHelper!

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 1.0.0
java-static fun createOrientationHelper(
    layoutManager: RecyclerView.LayoutManager!,
    orientation: Int
): OrientationHelper!

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 1.0.0
java-static fun createVerticalHelper(layoutManager: RecyclerView.LayoutManager!): OrientationHelper!

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 1.0.0
abstract fun getDecoratedEnd(view: View!): Int

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

getDecoratedMeasurement

Added in 1.0.0
abstract fun getDecoratedMeasurement(view: View!): Int

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

getDecoratedMeasurementInOther

Added in 1.0.0
abstract fun getDecoratedMeasurementInOther(view: View!): Int

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

getDecoratedStart

Added in 1.0.0
abstract fun getDecoratedStart(view: View!): Int

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
getDecoratedEnd

getEnd

Added in 1.0.0
abstract fun getEnd(): Int

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
abstract fun getEndAfterPadding(): Int

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
abstract fun getEndPadding(): Int

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
fun getLayoutManager(): RecyclerView.LayoutManager!

Returns the LayoutManager that is associated with this OrientationHelper.

getMode

Added in 1.0.0
abstract fun getMode(): Int

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

Returns
Int

The current measure spec mode.

getModeInOther

Added in 1.0.0
abstract fun getModeInOther(): Int

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

Returns
Int

The current measure spec mode.

getStartAfterPadding

Added in 1.0.0
abstract fun getStartAfterPadding(): Int

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
abstract fun getTotalSpace(): Int

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 1.0.0
fun getTotalSpaceChange(): Int

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 method.

Returns
Int

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

See also
onLayoutComplete

getTransformedEndWithDecoration

Added in 1.0.0
abstract fun getTransformedEndWithDecoration(view: View!): Int

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

getTransformedStartWithDecoration

Added in 1.0.0
abstract fun getTransformedStartWithDecoration(view: View!): Int

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

offsetChild

Added in 1.0.0
abstract fun offsetChild(view: View!, offset: Int): Unit

Offsets the child in this orientation.

Parameters
view: View!

View to offset

offset: Int

offset amount

offsetChildren

Added in 1.0.0
abstract fun offsetChildren(amount: Int): Unit

Offsets all children's positions by the given amount.

Parameters
amount: Int

Value to add to each child's layout parameters

onLayoutComplete

Added in 1.0.0
fun onLayoutComplete(): Unit

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.

Protected properties

mLayoutManager

Added in 1.0.0
protected val mLayoutManagerRecyclerView.LayoutManager!