-
public 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.
-
-
Field Summary
Fields Modifier and Type Field Description public final static int
HORIZONTAL
public final static int
VERTICAL
-
Method Summary
Modifier and Type Method Description RecyclerView.LayoutManager
getLayoutManager()
Returns the LayoutManager thatis associated with this OrientationHelper. 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 layoutcalculations. int
getTotalSpaceChange()
Returns the layout space change between the previous layout pass and current layout pass. abstract int
getDecoratedStart(View view)
Returns the start of the view including its decoration and margin. abstract int
getDecoratedEnd(View view)
Returns the end of the view including its decoration and margin. abstract int
getTransformedEndWithDecoration(View view)
Returns the end of the View after its matrix transformations are applied to its layoutposition. abstract int
getTransformedStartWithDecoration(View view)
Returns the start of the View after its matrix transformations are applied to its layoutposition. abstract int
getDecoratedMeasurement(View view)
Returns the space occupied by this View in the current orientation including decorations andmargins. abstract int
getDecoratedMeasurementInOther(View view)
Returns the space occupied by this View in the perpendicular orientation includingdecorations and margins. abstract int
getStartAfterPadding()
Returns the start position of the layout after the start padding is added. abstract int
getEndAfterPadding()
Returns the end position of the layout after the end padding is removed. abstract int
getEnd()
Returns the end position of the layout without taking padding into account. abstract void
offsetChildren(int amount)
Offsets all children's positions by the given amount. abstract int
getTotalSpace()
Returns the total space to layout. abstract void
offsetChild(View view, int offset)
Offsets the child in this orientation. 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. static OrientationHelper
createOrientationHelper(RecyclerView.LayoutManager layoutManager, int orientation)
Creates an OrientationHelper for the given LayoutManager and orientation. static OrientationHelper
createHorizontalHelper(RecyclerView.LayoutManager layoutManager)
Creates a horizontal OrientationHelper for the given LayoutManager. static OrientationHelper
createVerticalHelper(RecyclerView.LayoutManager layoutManager)
Creates a vertical OrientationHelper for the given LayoutManager. -
-
Method Detail
-
getLayoutManager
RecyclerView.LayoutManager getLayoutManager()
Returns the LayoutManager thatis associated with this OrientationHelper.
-
onLayoutComplete
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 layoutcalculations.
-
getTotalSpaceChange
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 method.
-
getDecoratedStart
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 leftdecoration and 3px left margin, returned value will be 15px.
- Parameters:
view
- The view element to check
-
getDecoratedEnd
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 rightdecoration and 3px right margin, returned value will be 205.
- Parameters:
view
- The view element to check
-
getTransformedEndWithDecoration
abstract int getTransformedEndWithDecoration(View view)
Returns the end of the View after its matrix transformations are applied to its layoutposition.
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
- The view whose transformed end will be returned
-
getTransformedStartWithDecoration
abstract int getTransformedStartWithDecoration(View view)
Returns the start of the View after its matrix transformations are applied to its layoutposition.
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
- The view whose transformed start will be returned
-
getDecoratedMeasurement
abstract int getDecoratedMeasurement(View view)
Returns the space occupied by this View in the current orientation including decorations andmargins.
- Parameters:
view
- The view element to check
-
getDecoratedMeasurementInOther
abstract int getDecoratedMeasurementInOther(View view)
Returns the space occupied by this View in the perpendicular orientation includingdecorations and margins.
- Parameters:
view
- The view element to check
-
getStartAfterPadding
abstract int getStartAfterPadding()
Returns the start position of the layout after the start padding is added.
-
getEndAfterPadding
abstract int getEndAfterPadding()
Returns the end position of the layout after the end padding is removed.
-
getEnd
abstract int getEnd()
Returns the end position of the layout without taking padding into account.
-
offsetChildren
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
-
getTotalSpace
abstract int getTotalSpace()
Returns the total space to layout. This number is the difference between getEndAfterPadding and getStartAfterPadding.
-
offsetChild
abstract void offsetChild(View view, int offset)
Offsets the child in this orientation.
- Parameters:
view
- View to offsetoffset
- offset amount
-
getEndPadding
abstract int getEndPadding()
Returns the padding at the end of the layout. For horizontal helper, this is the rightpadding and for vertical helper, this is the bottom padding. This method does not checkwhether the layout is RTL or not.
-
getMode
abstract int getMode()
Returns the MeasureSpec mode for the current orientation from the LayoutManager.
-
getModeInOther
abstract int getModeInOther()
Returns the MeasureSpec mode for the perpendicular orientation from the LayoutManager.
-
createOrientationHelper
static OrientationHelper createOrientationHelper(RecyclerView.LayoutManager layoutManager, int orientation)
Creates an OrientationHelper for the given LayoutManager and orientation.
- Parameters:
layoutManager
- LayoutManager to attach toorientation
- Desired orientation.
-
createHorizontalHelper
static OrientationHelper createHorizontalHelper(RecyclerView.LayoutManager layoutManager)
Creates a horizontal OrientationHelper for the given LayoutManager.
- Parameters:
layoutManager
- The LayoutManager to attach to.
-
createVerticalHelper
static OrientationHelper createVerticalHelper(RecyclerView.LayoutManager layoutManager)
Creates a vertical OrientationHelper for the given LayoutManager.
- Parameters:
layoutManager
- The LayoutManager to attach to.
-
-
-
-