Class FlexboxLayoutManager
-
- All Implemented Interfaces:
-
androidx.recyclerview.widget.RecyclerView.SmoothScroller.ScrollVectorProvider
,com.pointrlabs.core.util.flexbox.FlexContainer
public class FlexboxLayoutManager extends RecyclerView.LayoutManager implements FlexContainer, RecyclerView.SmoothScroller.ScrollVectorProvider
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public class
FlexboxLayoutManager.LayoutParams
LayoutParams used by the FlexboxLayoutManager, which stores per-child information required for the Flexbox. Note that some parent fields (which are not primitive nor a class implements Parcelable) are not included as the stored/restored fields after this class is serialized/de-serialized as an Parcelable.
-
Field Summary
Fields Modifier and Type Field Description public final static int
NOT_SET
-
Constructor Summary
Constructors Constructor Description FlexboxLayoutManager(Context context)
Creates a default FlexboxLayoutManager. FlexboxLayoutManager(Context context, int flexDirection)
Creates a FlexboxLayoutManager with the flexDirection specified. FlexboxLayoutManager(Context context, int flexDirection, int flexWrap)
Creates a FlexboxLayoutManager with the flexDirection and flexWrap attributes specified. FlexboxLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
Constructor used when layout manager is set in XML by RecyclerView attribute "layoutManager".
-
Method Summary
Modifier and Type Method Description int
getFlexDirection()
void
setFlexDirection(int flexDirection)
Sets the given flex direction attribute to the flex container. int
getFlexWrap()
void
setFlexWrap(int flexWrap)
Sets the given flex wrap attribute to the flex container. int
getJustifyContent()
void
setJustifyContent(int justifyContent)
Sets the given justify content attribute to the flex container. int
getAlignItems()
void
setAlignItems(int alignItems)
Sets the given align items attribute to the flex container. int
getAlignContent()
void
setAlignContent(int alignContent)
Sets the given align content attribute to the flex container. int
getMaxLine()
void
setMaxLine(int maxLine)
List<FlexLine>
getFlexLines()
int
getDecorationLengthMainAxis(View view, int index, int indexInFlexLine)
Returns the length of decoration (such as dividers) of the flex item along the main axis. int
getDecorationLengthCrossAxis(View view)
Returns the length of decoration (such as dividers) of the flex item along the cross axis. void
onNewFlexItemAdded(View view, int index, int indexInFlexLine, FlexLine flexLine)
Callback when a new flex item is added to the current container int
getFlexItemCount()
View
getFlexItemAt(int index)
View
getReorderedFlexItemAt(int index)
Returns a View for the given index. void
onNewFlexLineAdded(FlexLine flexLine)
Callback when a new flex line is added to the current container int
getChildWidthMeasureSpec(int widthSpec, int padding, int childDimension)
Returns the child measure spec for its width. int
getChildHeightMeasureSpec(int heightSpec, int padding, int childDimension)
Returns the child measure spec for its height. int
getLargestMainSize()
int
getSumOfCrossSize()
void
setFlexLines(List<FlexLine> flexLines)
Sets the list of the flex lines that compose the flex container to the one received as an argument. List<FlexLine>
getFlexLinesInternal()
void
updateViewCache(int position, View view)
Update the view cache in the flex container. PointF
computeScrollVectorForPosition(int targetPosition)
RecyclerView.LayoutParams
generateDefaultLayoutParams()
RecyclerView.LayoutParams
generateLayoutParams(Context c, AttributeSet attrs)
boolean
checkLayoutParams(RecyclerView.LayoutParams lp)
void
onAdapterChanged(RecyclerView.Adapter oldAdapter, RecyclerView.Adapter newAdapter)
Parcelable
onSaveInstanceState()
void
onRestoreInstanceState(Parcelable state)
void
onItemsAdded(RecyclerView recyclerView, int positionStart, int itemCount)
void
onItemsUpdated(RecyclerView recyclerView, int positionStart, int itemCount, Object payload)
void
onItemsUpdated(RecyclerView recyclerView, int positionStart, int itemCount)
void
onItemsRemoved(RecyclerView recyclerView, int positionStart, int itemCount)
void
onItemsMoved(RecyclerView recyclerView, int from, int to, int itemCount)
void
onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state)
void
setMaxLines(int maxLines)
void
onLayoutCompleted(RecyclerView.State state)
boolean
isMainAxisDirectionHorizontal()
Returns true if the main axis is horizontal, false otherwise. void
scrollToPosition(int position)
void
smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position)
boolean
getRecycleChildrenOnDetach()
void
setRecycleChildrenOnDetach(boolean recycleChildrenOnDetach)
Set whether this LayoutManager will recycle its children when it is detached from RecyclerView. void
onAttachedToWindow(RecyclerView recyclerView)
void
onDetachedFromWindow(RecyclerView view, RecyclerView.Recycler recycler)
boolean
canScrollHorizontally()
boolean
canScrollVertically()
int
scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State state)
int
scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state)
int
computeHorizontalScrollExtent(RecyclerView.State state)
int
computeVerticalScrollExtent(RecyclerView.State state)
int
computeHorizontalScrollOffset(RecyclerView.State state)
int
computeVerticalScrollOffset(RecyclerView.State state)
int
computeHorizontalScrollRange(RecyclerView.State state)
int
computeVerticalScrollRange(RecyclerView.State state)
int
findFirstVisibleItemPosition()
Returns the adapter position of the first visible view. int
findFirstCompletelyVisibleItemPosition()
Returns the adapter position of the first fully visible view. int
findLastVisibleItemPosition()
Returns the adapter position of the last visible view. int
findLastCompletelyVisibleItemPosition()
Returns the adapter position of the last fully visible view. -
Methods inherited from class androidx.recyclerview.widget.RecyclerView.LayoutManager
addDisappearingView, addView, assertInLayoutOrScroll, assertNotInLayoutOrScroll, attachView, calculateItemDecorationsForChild, chooseSize, collectAdjacentPrefetchPositions, collectInitialPrefetchPositions, detachAndScrapAttachedViews, detachAndScrapView, detachAndScrapViewAt, detachView, detachViewAt, endAnimation, findContainingItemView, findViewByPosition, generateLayoutParams, getBaseline, getBottomDecorationHeight, getChildAt, getChildCount, getChildMeasureSpec, getClipToPadding, getColumnCountForAccessibility, getDecoratedBottom, getDecoratedBoundsWithMargins, getDecoratedLeft, getDecoratedMeasuredHeight, getDecoratedMeasuredWidth, getDecoratedRight, getDecoratedTop, getFocusedChild, getHeight, getHeightMode, getItemCount, getItemViewType, getLayoutDirection, getLeftDecorationWidth, getMinimumHeight, getMinimumWidth, getPaddingBottom, getPaddingEnd, getPaddingLeft, getPaddingRight, getPaddingStart, getPaddingTop, getPosition, getProperties, getRightDecorationWidth, getRowCountForAccessibility, getSelectionModeForAccessibility, getTopDecorationHeight, getTransformedBoundingBox, getWidth, getWidthMode, hasFocus, ignoreView, isAttachedToWindow, isAutoMeasureEnabled, isFocused, isItemPrefetchEnabled, isLayoutHierarchical, isMeasurementCacheEnabled, isSmoothScrolling, isViewPartiallyVisible, layoutDecorated, layoutDecoratedWithMargins, measureChild, measureChildWithMargins, moveView, offsetChildrenHorizontal, offsetChildrenVertical, onAddFocusables, onDetachedFromWindow, onFocusSearchFailed, onInitializeAccessibilityEvent, onInterceptFocusSearch, onItemsChanged, onMeasure, onRequestChildFocus, onScrollStateChanged, postOnAnimation, removeAllViews, removeAndRecycleAllViews, removeAndRecycleView, removeAndRecycleViewAt, removeCallbacks, removeDetachedView, removeView, removeViewAt, requestChildRectangleOnScreen, requestLayout, requestSimpleAnimationsInNextLayout, setAutoMeasureEnabled, setItemPrefetchEnabled, setMeasuredDimension, setMeasurementCacheEnabled, startSmoothScroll, stopIgnoringView, supportsPredictiveItemAnimations
-
Methods inherited from class com.pointrlabs.core.util.flexbox.FlexContainer
addView, addView, getPaddingBottom, getPaddingEnd, getPaddingLeft, getPaddingRight, getPaddingStart, getPaddingTop, removeAllViews, removeViewAt
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
FlexboxLayoutManager
FlexboxLayoutManager(Context context)
Creates a default FlexboxLayoutManager.
-
FlexboxLayoutManager
FlexboxLayoutManager(Context context, int flexDirection)
Creates a FlexboxLayoutManager with the flexDirection specified.- Parameters:
flexDirection
- the flex direction attribute
-
FlexboxLayoutManager
FlexboxLayoutManager(Context context, int flexDirection, int flexWrap)
Creates a FlexboxLayoutManager with the flexDirection and flexWrap attributes specified.- Parameters:
flexDirection
- the flex direction attributeflexWrap
- the flex wrap attribute
-
FlexboxLayoutManager
FlexboxLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
Constructor used when layout manager is set in XML by RecyclerView attribute "layoutManager".
-
-
Method Detail
-
getFlexDirection
int getFlexDirection()
- Returns:
the flex direction attribute of the flex container.
-
setFlexDirection
void setFlexDirection(int flexDirection)
Sets the given flex direction attribute to the flex container.
- Parameters:
flexDirection
- the flex direction value
-
getFlexWrap
int getFlexWrap()
- Returns:
the flex wrap attribute of the flex container.
-
setFlexWrap
void setFlexWrap(int flexWrap)
Sets the given flex wrap attribute to the flex container.
- Parameters:
flexWrap
- the flex wrap value
-
getJustifyContent
int getJustifyContent()
- Returns:
the justify content attribute of the flex container.
-
setJustifyContent
void setJustifyContent(int justifyContent)
Sets the given justify content attribute to the flex container.
- Parameters:
justifyContent
- the justify content value
-
getAlignItems
int getAlignItems()
- Returns:
the align items attribute of the flex container.
-
setAlignItems
void setAlignItems(int alignItems)
Sets the given align items attribute to the flex container.
- Parameters:
alignItems
- the align items value
-
getAlignContent
int getAlignContent()
- Returns:
the align content attribute of the flex container.
-
setAlignContent
void setAlignContent(int alignContent)
Sets the given align content attribute to the flex container.
- Parameters:
alignContent
- the align content value
-
getMaxLine
int getMaxLine()
- Returns:
the current value of the maximum number of flex lines. If not set, NOT_SET is returned.
-
setMaxLine
void setMaxLine(int maxLine)
- Parameters:
maxLine
- the int value, which specifies the maximum number of flex lines
-
getFlexLines
List<FlexLine> getFlexLines()
- Returns:
the flex lines composing this flex container. The overridden method should return a copy of the original list excluding a dummy flex line (flex line that doesn't have any flex items in it but used for the alignment along the cross axis) so that any changes of the returned list are not reflected to the original list.
-
getDecorationLengthMainAxis
int getDecorationLengthMainAxis(View view, int index, int indexInFlexLine)
Returns the length of decoration (such as dividers) of the flex item along the main axis.
- Parameters:
view
- the view from which the length of the decoration is retrievedindex
- the absolute index of the flex item within the flex containerindexInFlexLine
- the relative index of the flex item within the flex line- Returns:
the length of the decoration. Note that the length of the flex item itself is not included in the result.
-
getDecorationLengthCrossAxis
int getDecorationLengthCrossAxis(View view)
Returns the length of decoration (such as dividers) of the flex item along the cross axis.
- Parameters:
view
- the view from which the length of the decoration is retrieved- Returns:
the length of the decoration. Note that the length of the flex item itself is not included in the result.
-
onNewFlexItemAdded
void onNewFlexItemAdded(View view, int index, int indexInFlexLine, FlexLine flexLine)
Callback when a new flex item is added to the current container
- Parameters:
view
- the view as a flex item which is addedindex
- the absolute index of the flex item addedindexInFlexLine
- the relative index of the flex item added within the flex lineflexLine
- the flex line where the new flex item is added
-
getFlexItemCount
int getFlexItemCount()
- Returns:
the number of flex items contained in the flex container. This method doesn't always reflect the latest state of the adapter. If you want to access the latest state of the adapter, use the RecyclerView.State instance passed as an argument for some methods (such as onLayoutChildren) This method is used to avoid the implementation of the similar method. i.e. getChildCount returns the child count, but it doesn't include the children that are detached or scrapped.
-
getFlexItemAt
View getFlexItemAt(int index)
- Returns:
the flex item as a view specified as the index. This method doesn't always return the latest state of the view in the adapter. If you want to access the latest state, use the RecyclerView.Recycler instance passed as an argument for some methods (such as onLayoutChildren) This method is used to avoid the implementation of the similar method. i.e. getChildAt returns a view for the given index, but the index is based on the layout position, not based on the adapter position, which isn't desired given the usage of this method.
-
getReorderedFlexItemAt
View getReorderedFlexItemAt(int index)
Returns a View for the given index. The order attribute (getOrder) is not supported by this class since otherwise all view holders need to be inflated at least once even though only the visible part of the layout is needed. Implementing this method just to make this class conform to the FlexContainer interface.
- Parameters:
index
- the index of the view- Returns:
the view for the given index. If the index is negative or out of bounds of the number of contained views, returns
null
.
-
onNewFlexLineAdded
void onNewFlexLineAdded(FlexLine flexLine)
Callback when a new flex line is added to the current container
- Parameters:
flexLine
- the new added flex line
-
getChildWidthMeasureSpec
int getChildWidthMeasureSpec(int widthSpec, int padding, int childDimension)
Returns the child measure spec for its width.
- Parameters:
widthSpec
- the measure spec for the width imposed by the parentpadding
- the padding along the width for the parentchildDimension
- the value of the child dimension
-
getChildHeightMeasureSpec
int getChildHeightMeasureSpec(int heightSpec, int padding, int childDimension)
Returns the child measure spec for its height.
- Parameters:
heightSpec
- the measure spec for the height imposed by the parentpadding
- the padding along the height for the parentchildDimension
- the value of the child dimension
-
getLargestMainSize
int getLargestMainSize()
- Returns:
the largest main size of all flex lines including decorator lengths.
-
getSumOfCrossSize
int getSumOfCrossSize()
- Returns:
the sum of the cross sizes of all flex lines including decorator lengths.
-
setFlexLines
void setFlexLines(List<FlexLine> flexLines)
Sets the list of the flex lines that compose the flex container to the one received as an argument.
- Parameters:
flexLines
- the list of flex lines
-
getFlexLinesInternal
List<FlexLine> getFlexLinesInternal()
- Returns:
the list of the flex lines including dummy flex lines (flex line that doesn't have any flex items in it but used for the alignment along the cross axis), which aren't included in the getFlexLines.
-
updateViewCache
void updateViewCache(int position, View view)
Update the view cache in the flex container.
- Parameters:
position
- the position of the view to be updatedview
- the view instance
-
computeScrollVectorForPosition
PointF computeScrollVectorForPosition(int targetPosition)
-
generateDefaultLayoutParams
RecyclerView.LayoutParams generateDefaultLayoutParams()
-
generateLayoutParams
RecyclerView.LayoutParams generateLayoutParams(Context c, AttributeSet attrs)
-
checkLayoutParams
boolean checkLayoutParams(RecyclerView.LayoutParams lp)
-
onAdapterChanged
void onAdapterChanged(RecyclerView.Adapter oldAdapter, RecyclerView.Adapter newAdapter)
-
onSaveInstanceState
Parcelable onSaveInstanceState()
-
onRestoreInstanceState
void onRestoreInstanceState(Parcelable state)
-
onItemsAdded
void onItemsAdded(RecyclerView recyclerView, int positionStart, int itemCount)
-
onItemsUpdated
void onItemsUpdated(RecyclerView recyclerView, int positionStart, int itemCount, Object payload)
-
onItemsUpdated
void onItemsUpdated(RecyclerView recyclerView, int positionStart, int itemCount)
-
onItemsRemoved
void onItemsRemoved(RecyclerView recyclerView, int positionStart, int itemCount)
-
onItemsMoved
void onItemsMoved(RecyclerView recyclerView, int from, int to, int itemCount)
-
onLayoutChildren
void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state)
-
setMaxLines
void setMaxLines(int maxLines)
-
onLayoutCompleted
void onLayoutCompleted(RecyclerView.State state)
-
isMainAxisDirectionHorizontal
boolean isMainAxisDirectionHorizontal()
Returns true if the main axis is horizontal, false otherwise.
- Returns:
true if the main axis is horizontal, false otherwise
-
scrollToPosition
void scrollToPosition(int position)
-
smoothScrollToPosition
void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position)
-
getRecycleChildrenOnDetach
boolean getRecycleChildrenOnDetach()
- Returns:
true if LayoutManager will recycle its children when it is detached from RecyclerView.
-
setRecycleChildrenOnDetach
void setRecycleChildrenOnDetach(boolean recycleChildrenOnDetach)
Set whether this LayoutManager will recycle its children when it is detached from RecyclerView.
If you are using a RecyclerView.RecycledViewPool, it might be a good idea to set this flag to
true
so that views will be available to other RecyclerViews immediately.Note that, setting this flag will result in a performance drop if RecyclerView is restored.
- Parameters:
recycleChildrenOnDetach
- Whether children should be recycled in detach or not.
-
onAttachedToWindow
void onAttachedToWindow(RecyclerView recyclerView)
-
onDetachedFromWindow
void onDetachedFromWindow(RecyclerView view, RecyclerView.Recycler recycler)
-
canScrollHorizontally
boolean canScrollHorizontally()
-
canScrollVertically
boolean canScrollVertically()
-
scrollHorizontallyBy
int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State state)
-
scrollVerticallyBy
int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state)
-
computeHorizontalScrollExtent
int computeHorizontalScrollExtent(RecyclerView.State state)
-
computeVerticalScrollExtent
int computeVerticalScrollExtent(RecyclerView.State state)
-
computeHorizontalScrollOffset
int computeHorizontalScrollOffset(RecyclerView.State state)
-
computeVerticalScrollOffset
int computeVerticalScrollOffset(RecyclerView.State state)
-
computeHorizontalScrollRange
int computeHorizontalScrollRange(RecyclerView.State state)
-
computeVerticalScrollRange
int computeVerticalScrollRange(RecyclerView.State state)
-
findFirstVisibleItemPosition
int findFirstVisibleItemPosition()
Returns the adapter position of the first visible view. This position does not include adapter changes that were dispatched after the last layout pass. If RecyclerView has item decorators, they will be considered in calculations as well. LayoutManager may pre-cache some views that are not necessarily visible. Those views are ignored in this method.
- Returns:
The adapter position of the first visible item or NO_POSITION if there aren't any visible items.
-
findFirstCompletelyVisibleItemPosition
int findFirstCompletelyVisibleItemPosition()
Returns the adapter position of the first fully visible view. This position does not include adapter changes that were dispatched after the last layout pass.
- Returns:
The adapter position of the first fully visible item or NO_POSITION if there aren't any visible items.
-
findLastVisibleItemPosition
int findLastVisibleItemPosition()
Returns the adapter position of the last visible view. This position does not include adapter changes that were dispatched after the last layout pass. If RecyclerView has item decorators, they will be considered in calculations as well. LayoutManager may pre-cache some views that are not necessarily visible. Those views are ignored in this method.
- Returns:
The adapter position of the last visible view or NO_POSITION if there aren't any visible items.
-
findLastCompletelyVisibleItemPosition
int findLastCompletelyVisibleItemPosition()
Returns the adapter position of the last fully visible view. This position does not include adapter changes that were dispatched after the last layout pass.
- Returns:
The adapter position of the last fully visible view or NO_POSITION if there aren't any visible items.
-
-
-
-