public abstract class OrientationHelper extends Object
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.
Modifier and Type | Field and Description |
---|---|
static int |
HORIZONTAL |
protected RecyclerView.LayoutManager |
mLayoutManager |
static int |
VERTICAL |
Modifier and Type | Method and Description |
---|---|
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.
|
protected final RecyclerView.LayoutManager mLayoutManager
public static final int HORIZONTAL
public static final int VERTICAL
public void onLayoutComplete()
public int getTotalSpaceChange()
Make sure you call onLayoutComplete()
at the end of your LayoutManager's
RecyclerView.LayoutManager.onLayoutChildren(RecyclerView.Recycler,
RecyclerView.State)
method.
onLayoutComplete()
public abstract int getDecoratedStart(View view)
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.
view
- The view element to checkgetDecoratedEnd(android.view.View)
public abstract int getDecoratedEnd(View view)
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.
view
- The view element to checkgetDecoratedStart(android.view.View)
public abstract int getTransformedEndWithDecoration(View view)
This method is useful when trying to detect the visible edge of a View.
It includes the decorations but does not include the margins.
view
- The view whose transformed end will be returnedRecyclerView.LayoutManager.getTransformedBoundingBox(View, boolean, Rect)
public abstract int getTransformedStartWithDecoration(View view)
This method is useful when trying to detect the visible edge of a View.
It includes the decorations but does not include the margins.
view
- The view whose transformed start will be returnedRecyclerView.LayoutManager.getTransformedBoundingBox(View, boolean, Rect)
public abstract int getDecoratedMeasurement(View view)
view
- The view element to checkgetDecoratedMeasurementInOther(View)
public abstract int getDecoratedMeasurementInOther(View view)
view
- The view element to checkgetDecoratedMeasurement(View)
public abstract int getStartAfterPadding()
public abstract int getEndAfterPadding()
public abstract int getEnd()
public abstract void offsetChildren(int amount)
amount
- Value to add to each child's layout parameterspublic abstract int getTotalSpace()
getEndAfterPadding()
and getStartAfterPadding()
.public abstract void offsetChild(View view, int offset)
view
- View to offsetoffset
- offset amountpublic abstract int getEndPadding()
public abstract int getMode()
View.MeasureSpec
,
RecyclerView.LayoutManager.getWidthMode()
,
RecyclerView.LayoutManager.getHeightMode()
public abstract int getModeInOther()
View.MeasureSpec
,
RecyclerView.LayoutManager.getWidthMode()
,
RecyclerView.LayoutManager.getHeightMode()
public static OrientationHelper createOrientationHelper(RecyclerView.LayoutManager layoutManager, int orientation)
layoutManager
- LayoutManager to attach toorientation
- Desired orientation. Should be HORIZONTAL
or VERTICAL
public static OrientationHelper createHorizontalHelper(RecyclerView.LayoutManager layoutManager)
layoutManager
- The LayoutManager to attach to.public static OrientationHelper createVerticalHelper(RecyclerView.LayoutManager layoutManager)
layoutManager
- The LayoutManager to attach to.