Class FlowLayoutManager
-
- All Implemented Interfaces:
public class FlowLayoutManager extends RecyclerView.LayoutManager
A RecyclerView.LayoutManager that lays out items in flow style: items are placed in a line until it is full, then a new line starts, like words in a paragraph.
Items can have different sizes. It supports predictive item animations, scroll and smooth scroll, auto measurement, left, right or center alignment (setAlignment), a limit of items per line (maxItemsPerLine, singleItemPerLine) and a limit of lines (maxLines).
recyclerView.setLayoutManager(new FlowLayoutManager() .setAlignment(Alignment.LEFT) .maxItemsPerLine(3));
-
-
Constructor Summary
Constructors Constructor Description FlowLayoutManager()Creates a layout manager with centered lines and no limits. FlowLayoutManager(int maxLines)Creates a layout manager with centered lines that shows at most maxLineslines.
-
Method Summary
Modifier and Type Method Description RecyclerView.LayoutParamsgenerateDefaultLayoutParams()voidonLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state)booleancanScrollHorizontally()booleancanScrollVertically()booleancanScrollVertically(int direction)Check if this view can be scrolled vertically in a certain direction. intscrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state)voidonItemsChanged(RecyclerView recyclerView)voidonItemsAdded(RecyclerView recyclerView, int positionStart, int itemCount)voidonItemsRemoved(RecyclerView recyclerView, int positionStart, int itemCount)voidonItemsUpdated(RecyclerView recyclerView, int positionStart, int itemCount)voidonItemsUpdated(RecyclerView recyclerView, int positionStart, int itemCount, Object payload)voidonItemsMoved(RecyclerView recyclerView, int from, int to, int itemCount)voidonAttachedToWindow(RecyclerView view)voidonDetachedFromWindow(RecyclerView view, RecyclerView.Recycler recycler)booleansupportsPredictiveItemAnimations()voidscrollToPosition(int position)voidsmoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position)voidsetAutoMeasureEnabled(boolean enabled)intgetChildLayoutPosition(View child)FlowLayoutManagersetAlignment(Alignment alignment)Sets the alignment of the items in each line, CENTER by default. FlowLayoutManagersingleItemPerLine()Puts each item in its own line, same as maxItemsPerLine(1).FlowLayoutManagermaxItemsPerLine(int itemsPerLine)Puts at most itemsPerLineitems in each line.FlowLayoutManagermaxLines(int maxLines)Shows at most maxLineslines, items after the last line are not laid out.FlowLayoutManagerremoveMaxLinesLimit()Shows all lines, removing the limit set with maxLines. FlowLayoutManagerremoveItemPerLineLimit()Puts as many items in a line as fit, removing the limit set with maxItemsPerLine or singleItemPerLine. intcomputeVerticalScrollExtent(RecyclerView.State state)intcomputeVerticalScrollOffset(RecyclerView.State state)intcomputeVerticalScrollRange(RecyclerView.State state)-
Methods inherited from class androidx.recyclerview.widget.RecyclerView.LayoutManager
addDisappearingView, addView, assertInLayoutOrScroll, assertNotInLayoutOrScroll, attachView, calculateItemDecorationsForChild, checkLayoutParams, chooseSize, collectAdjacentPrefetchPositions, collectInitialPrefetchPositions, computeHorizontalScrollExtent, computeHorizontalScrollOffset, computeHorizontalScrollRange, 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, isLayoutReversed, isMeasurementCacheEnabled, isSmoothScrolling, isViewPartiallyVisible, layoutDecorated, layoutDecoratedWithMargins, measureChild, measureChildWithMargins, moveView, offsetChildrenHorizontal, offsetChildrenVertical, onAdapterChanged, onAddFocusables, onDetachedFromWindow, onFocusSearchFailed, onInitializeAccessibilityEvent, onInterceptFocusSearch, onLayoutCompleted, onMeasure, onRequestChildFocus, onRestoreInstanceState, onSaveInstanceState, onScrollStateChanged, postOnAnimation, removeAllViews, removeAndRecycleAllViews, removeAndRecycleView, removeAndRecycleViewAt, removeCallbacks, removeDetachedView, removeView, removeViewAt, requestChildRectangleOnScreen, requestLayout, requestSimpleAnimationsInNextLayout, scrollHorizontallyBy, setItemPrefetchEnabled, setMeasuredDimension, setMeasurementCacheEnabled, startSmoothScroll, stopIgnoringView -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
FlowLayoutManager
FlowLayoutManager()
Creates a layout manager with centered lines and no limits.
-
FlowLayoutManager
FlowLayoutManager(int maxLines)
Creates a layout manager with centered lines that shows at most
maxLineslines.- Parameters:
maxLines- max number of lines to show, <= 0 to show all lines.
-
-
Method Detail
-
generateDefaultLayoutParams
RecyclerView.LayoutParams generateDefaultLayoutParams()
-
onLayoutChildren
void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state)
-
canScrollHorizontally
boolean canScrollHorizontally()
-
canScrollVertically
boolean canScrollVertically()
-
canScrollVertically
boolean canScrollVertically(int direction)
Check if this view can be scrolled vertically in a certain direction.
- Parameters:
direction- Negative to check scrolling up, positive to check scrolling down.- Returns:
true if this view can be scrolled in the specified direction, false otherwise.
-
scrollVerticallyBy
int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state)
-
onItemsChanged
void onItemsChanged(RecyclerView recyclerView)
-
onItemsAdded
void onItemsAdded(RecyclerView recyclerView, int positionStart, int itemCount)
-
onItemsRemoved
void onItemsRemoved(RecyclerView recyclerView, int positionStart, int itemCount)
-
onItemsUpdated
void onItemsUpdated(RecyclerView recyclerView, int positionStart, int itemCount)
-
onItemsUpdated
void onItemsUpdated(RecyclerView recyclerView, int positionStart, int itemCount, Object payload)
-
onItemsMoved
void onItemsMoved(RecyclerView recyclerView, int from, int to, int itemCount)
-
onAttachedToWindow
void onAttachedToWindow(RecyclerView view)
-
onDetachedFromWindow
void onDetachedFromWindow(RecyclerView view, RecyclerView.Recycler recycler)
-
supportsPredictiveItemAnimations
boolean supportsPredictiveItemAnimations()
-
scrollToPosition
void scrollToPosition(int position)
-
smoothScrollToPosition
void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position)
-
setAutoMeasureEnabled
void setAutoMeasureEnabled(boolean enabled)
-
getChildLayoutPosition
int getChildLayoutPosition(View child)
- Parameters:
child- a child view of the RecyclerView- Returns:
the layout position of
child
-
setAlignment
FlowLayoutManager setAlignment(Alignment alignment)
Sets the alignment of the items in each line, CENTER by default.
- Parameters:
alignment- the alignment- Returns:
this layout manager
-
singleItemPerLine
FlowLayoutManager singleItemPerLine()
Puts each item in its own line, same as
maxItemsPerLine(1).- Returns:
this layout manager
-
maxItemsPerLine
FlowLayoutManager maxItemsPerLine(int itemsPerLine)
Puts at most
itemsPerLineitems in each line.- Parameters:
itemsPerLine- max number of items in a line, <= 0 for no limit- Returns:
this layout manager
-
maxLines
FlowLayoutManager maxLines(int maxLines)
Shows at most
maxLineslines, items after the last line are not laid out.- Parameters:
maxLines- max number of lines to show, <= 0 to show all lines- Returns:
this layout manager
-
removeMaxLinesLimit
FlowLayoutManager removeMaxLinesLimit()
Shows all lines, removing the limit set with maxLines.
- Returns:
this layout manager
-
removeItemPerLineLimit
FlowLayoutManager removeItemPerLineLimit()
Puts as many items in a line as fit, removing the limit set with maxItemsPerLine or singleItemPerLine.
- Returns:
this layout manager
-
computeVerticalScrollExtent
int computeVerticalScrollExtent(RecyclerView.State state)
-
computeVerticalScrollOffset
int computeVerticalScrollOffset(RecyclerView.State state)
-
computeVerticalScrollRange
int computeVerticalScrollRange(RecyclerView.State state)
-
-
-
-