LayoutManager
A LayoutManager
is responsible for measuring and positioning item views within a RecyclerView
as well as determining the policy for when to recycle item views that are no longer visible to the user. By changing the LayoutManager
a RecyclerView
can be used to implement a standard vertically scrolling list, a uniform grid, staggered grids, horizontally scrolling collections and more. Several stock layout managers are provided for general use.
int
, int
), RecyclerView will instantiate and set the LayoutManager when being inflated. Most used properties can be then obtained from getProperties. In case a LayoutManager specifies both constructors, the non-default constructor will take precedence.Inheritors
Types
Link copied to clipboard
interface LayoutPrefetchRegistry
Interface for LayoutManagers to request items to be prefetched, based on position, with specified distance from viewport, which indicates priority.
Link copied to clipboard
Some general properties that a LayoutManager may want to use.
Functions
Link copied to clipboard
To be called only during onLayoutChildren to add a view to the layout that is known to be going away, either because it has been removed or because it is actually not in the visible portion of the container but is being laid out in order to inform RecyclerView in how to animate the item out of view.
Link copied to clipboard
Checks if RecyclerView is in the middle of a layout or scroll and throws an IllegalStateException if it is not.
Link copied to clipboard
Checks if RecyclerView is in the middle of a layout or scroll and throws an IllegalStateException if it is.
Link copied to clipboard
Reattach a previously detached view.
Link copied to clipboard
Calculates the item decor insets applied to the given child and updates the provided Rect instance with the inset values.
Link copied to clipboard
Query if horizontal scrolling is currently supported.
Link copied to clipboard
Query if vertical scrolling is currently supported.
Link copied to clipboard
Determines the validity of the supplied LayoutParams object.
Link copied to clipboard
Chooses a size from the given specs and parameters that is closest to the desired size and also complies with the spec.
Link copied to clipboard
open fun collectAdjacentPrefetchPositions(dx: Int, dy: Int, state: RecyclerView.State, layoutPrefetchRegistry: RecyclerView.LayoutManager.LayoutPrefetchRegistry)
Gather all positions from the LayoutManager to be prefetched, given specified momentum.
Link copied to clipboard
open fun collectInitialPrefetchPositions(adapterItemCount: Int, layoutPrefetchRegistry: RecyclerView.LayoutManager.LayoutPrefetchRegistry)
Gather all positions from the LayoutManager to be prefetched in preperation for its RecyclerView to come on screen, due to the movement of another, containing RecyclerView.
Link copied to clipboard
Override this method if you want to support scroll bars.
Link copied to clipboard
Override this method if you want to support scroll bars.
Link copied to clipboard
Override this method if you want to support scroll bars.
Link copied to clipboard
Override this method if you want to support scroll bars.
Link copied to clipboard
Override this method if you want to support scroll bars.
Link copied to clipboard
Override this method if you want to support scroll bars.
Link copied to clipboard
Temporarily detach and scrap all currently attached child views.
Link copied to clipboard
Detach a child view and add it to a Recycler's scrap heap.
Link copied to clipboard
Detach a child view and add it to a Recycler's scrap heap.
Link copied to clipboard
Temporarily detach a child view.
Link copied to clipboard
Temporarily detach a child view.
Link copied to clipboard
Ends all animations on the view created by the ItemAnimator.
Link copied to clipboard
Traverses the ancestors of the given view and returns the item view that contains it and also a direct child of the LayoutManager.
Link copied to clipboard
Finds the view which represents the given adapter position.
Link copied to clipboard
Create a default
LayoutParams
object for a child of the RecyclerView.Link copied to clipboard
Create a LayoutParams object suitable for this LayoutManager, copying relevant values from the supplied LayoutParams object if possible.
Create a LayoutParams object suitable for this LayoutManager from an inflated layout resource.
Link copied to clipboard
Returns offset of the RecyclerView's text baseline from the its top boundary.
Link copied to clipboard
Returns the total height of item decorations applied to child's bottom.
Link copied to clipboard
Return the child view at the given index
Link copied to clipboard
Return the current number of child views attached to the parent RecyclerView.
Link copied to clipboard
open fun getChildMeasureSpec(parentSize: Int, padding: Int, childDimension: Int, canScroll: Boolean): Int
open fun getChildMeasureSpec(parentSize: Int, parentMode: Int, padding: Int, childDimension: Int, canScroll: Boolean): Int
Calculate a MeasureSpec value for measuring a child view in one dimension.
Link copied to clipboard
Check if the RecyclerView is configured to clip child views to its padding.
Link copied to clipboard
open fun getColumnCountForAccessibility(@NonNull recycler: RecyclerView.Recycler, @NonNull state: RecyclerView.State): Int
Returns the number of columns for accessibility.
Link copied to clipboard
Returns the bottom edge of the given child view within its parent, offset by any applied ItemDecorations.
Link copied to clipboard
Returns the bounds of the view including its decoration and margins.
Link copied to clipboard
Returns the left edge of the given child view within its parent, offset by any applied ItemDecorations.
Link copied to clipboard
Returns the measured height of the given child, plus the additional size of any insets applied by ItemDecorations.
Link copied to clipboard
Returns the measured width of the given child, plus the additional size of any insets applied by ItemDecorations.
Link copied to clipboard
Returns the right edge of the given child view within its parent, offset by any applied ItemDecorations.
Link copied to clipboard
Returns the top edge of the given child view within its parent, offset by any applied ItemDecorations.
Link copied to clipboard
Returns the item View which has or contains focus.
Link copied to clipboard
Return the height measurement spec mode that is currently relevant to the LayoutManager.
Link copied to clipboard
Returns the number of items in the adapter bound to the parent RecyclerView.
Link copied to clipboard
Returns the View type defined by the adapter.
Link copied to clipboard
Returns the resolved layout direction for this RecyclerView.
Link copied to clipboard
Returns the total width of item decorations applied to child's left.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Return the bottom padding of the parent RecyclerView
Link copied to clipboard
Return the end padding of the parent RecyclerView
Link copied to clipboard
Return the left padding of the parent RecyclerView
Link copied to clipboard
Return the right padding of the parent RecyclerView
Link copied to clipboard
Return the start padding of the parent RecyclerView
Link copied to clipboard
Return the top padding of the parent RecyclerView
Link copied to clipboard
Returns the adapter position of the item represented by the given View.
Link copied to clipboard
open fun getProperties(@NonNull context: Context, @Nullable attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int): RecyclerView.LayoutManager.Properties
Parse the xml attributes to get the most common properties used by layout managers.
Link copied to clipboard
Returns the total width of item decorations applied to child's right.
Link copied to clipboard
open fun getRowCountForAccessibility(@NonNull recycler: RecyclerView.Recycler, @NonNull state: RecyclerView.State): Int
Returns the number of rows for accessibility.
Link copied to clipboard
open fun getSelectionModeForAccessibility(@NonNull recycler: RecyclerView.Recycler, @NonNull state: RecyclerView.State): Int
Returns the selection mode for accessibility.
Link copied to clipboard
Returns the total height of item decorations applied to child's top.
Link copied to clipboard
Link copied to clipboard
Return the width measurement spec mode that is currently relevant to the LayoutManager.
Link copied to clipboard
Flags a view so that it will not be scrapped or recycled.
Link copied to clipboard
Returns whether LayoutManager is currently attached to a RecyclerView which is attached to a window.
Link copied to clipboard
Returns whether the measuring pass of layout should use the AutoMeasure mechanism of RecyclerView or if it should be done by the LayoutManager's implementation of onMeasure.
Link copied to clipboard
Sets whether the LayoutManager should be queried for views outside of its viewport while the UI thread is idle between frames.
Link copied to clipboard
open fun isLayoutHierarchical(@NonNull recycler: RecyclerView.Recycler, @NonNull state: RecyclerView.State): Boolean
Returns whether layout is hierarchical or not to be used for accessibility.
Link copied to clipboard
Query if the layout is in reverse order.
Link copied to clipboard
In addition to the View Framework's measurement cache, RecyclerView uses its own additional measurement cache for its children to avoid re-measuring them when not necessary.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Lay out the given child view within the RecyclerView using coordinates that include any current ItemDecorations.
Link copied to clipboard
open fun layoutDecoratedWithMargins(@NonNull child: View, left: Int, top: Int, right: Int, bottom: Int)
Lay out the given child view within the RecyclerView using coordinates that include any current ItemDecorations and margins.
Link copied to clipboard
Measure a child view using standard measurement policy, taking the padding of the parent RecyclerView and any added item decorations into account.
Link copied to clipboard
Measure a child view using standard measurement policy, taking the padding of the parent RecyclerView, any added item decorations and the child margins into account.
Link copied to clipboard
Offset all child views attached to the parent RecyclerView by dx pixels along the horizontal axis.
Link copied to clipboard
Offset all child views attached to the parent RecyclerView by dy pixels along the vertical axis.
Link copied to clipboard
open fun onAdapterChanged(@Nullable oldAdapter: RecyclerView.Adapter, @Nullable newAdapter: RecyclerView.Adapter)
Called if the RecyclerView this LayoutManager is bound to has a different adapter set via setAdapter or swapAdapter.
Link copied to clipboard
open fun onAddFocusables(@NonNull recyclerView: RecyclerView, @NonNull views: ArrayList<View>, direction: Int, focusableMode: Int): Boolean
Called to populate focusable views within the RecyclerView.
Link copied to clipboard
Called when this LayoutManager is both attached to a RecyclerView and that RecyclerView is attached to a window.
Link copied to clipboard
Called when this LayoutManager is detached from its parent RecyclerView or when its parent RecyclerView is detached from its window.
Link copied to clipboard
open fun onFocusSearchFailed(@NonNull focused: View, direction: Int, @NonNull recycler: RecyclerView.Recycler, @NonNull state: RecyclerView.State): View
Called when searching for a focusable view in the given direction has failed for the current content of the RecyclerView.
Link copied to clipboard
open fun onInitializeAccessibilityEvent(@NonNull recycler: RecyclerView.Recycler, @NonNull state: RecyclerView.State, @NonNull event: AccessibilityEvent)
Called by the accessibility delegate to initialize an accessibility event.
Link copied to clipboard
open fun onInitializeAccessibilityNodeInfo(@NonNull recycler: RecyclerView.Recycler, @NonNull state: RecyclerView.State, @NonNull info: AccessibilityNodeInfoCompat)
Called by the AccessibilityDelegate when the information about the current layout should be populated.
Link copied to clipboard
open fun onInitializeAccessibilityNodeInfoForItem(@NonNull recycler: RecyclerView.Recycler, @NonNull state: RecyclerView.State, @NonNull host: View, @NonNull info: AccessibilityNodeInfoCompat)
Called by the AccessibilityDelegate when the accessibility information for a specific item should be populated.
Link copied to clipboard
This method gives a LayoutManager an opportunity to intercept the initial focus search before the default behavior of FocusFinder is used.
Link copied to clipboard
Called when items have been added to the adapter.
Link copied to clipboard
Called in response to a call to notifyDataSetChanged or swapAdapter ()} and signals that the the entire data set has changed.
Link copied to clipboard
Called when an item is moved withing the adapter.
Link copied to clipboard
Called when items have been removed from the adapter.
Link copied to clipboard
Called when items have been changed in the adapter.
open fun onItemsUpdated(@NonNull recyclerView: RecyclerView, positionStart: Int, itemCount: Int, @Nullable payload: Any)
Called when items have been changed in the adapter and with optional payload.
Link copied to clipboard
Lay out all relevant child views from the given adapter.
Link copied to clipboard
Called after a full layout calculation is finished.
Link copied to clipboard
open fun onMeasure(@NonNull recycler: RecyclerView.Recycler, @NonNull state: RecyclerView.State, widthSpec: Int, heightSpec: Int)
Measure the attached RecyclerView.
Link copied to clipboard
open fun onRequestChildFocus(@NonNull parent: RecyclerView, @NonNull child: View, @Nullable focused: View): Boolean
open fun onRequestChildFocus(@NonNull parent: RecyclerView, @NonNull state: RecyclerView.State, @NonNull child: View, @Nullable focused: View): Boolean
Called when a descendant view of the RecyclerView requests focus.
Link copied to clipboard
Called when the RecyclerView is ready to restore the state based on a previous RecyclerView.
Link copied to clipboard
Called when the LayoutManager should save its state.
Link copied to clipboard
RecyclerView calls this method to notify LayoutManager that scroll state has changed.
Link copied to clipboard
open fun performAccessibilityAction(@NonNull recycler: RecyclerView.Recycler, @NonNull state: RecyclerView.State, action: Int, @Nullable args: Bundle): Boolean
Called by AccessibilityDelegate when an action is requested from the RecyclerView.
Link copied to clipboard
open fun performAccessibilityActionForItem(@NonNull recycler: RecyclerView.Recycler, @NonNull state: RecyclerView.State, @NonNull view: View, action: Int, @Nullable args: Bundle): Boolean
Called by AccessibilityDelegate when an accessibility action is requested on one of the children of LayoutManager.
Link copied to clipboard
Causes the Runnable to execute on the next animation time step.
Link copied to clipboard
Remove all views from the currently attached RecyclerView.
Link copied to clipboard
Removes all views and recycles them using the given recycler.
Link copied to clipboard
Remove a child view and recycle it using the given Recycler.
Link copied to clipboard
Remove a child view and recycle it using the given Recycler.
Link copied to clipboard
Removes the specified Runnable from the message queue.
Link copied to clipboard
Finish removing a view that was previously temporarily detached.
Link copied to clipboard
Remove a view from the currently attached RecyclerView if needed.
Link copied to clipboard
Remove a view from the currently attached RecyclerView if needed.
Link copied to clipboard
open fun requestChildRectangleOnScreen(@NonNull parent: RecyclerView, @NonNull child: View, @NonNull rect: Rect, immediate: Boolean): Boolean
Called when a child of the RecyclerView wants a particular rectangle to be positioned onto the screen.
open fun requestChildRectangleOnScreen(@NonNull parent: RecyclerView, @NonNull child: View, @NonNull rect: Rect, immediate: Boolean, focusedChildVisible: Boolean): Boolean
Requests that the given child of the RecyclerView be positioned onto the screen.
Link copied to clipboard
Calls
RecyclerView#requestLayout
on the underlying RecyclerViewLink copied to clipboard
A LayoutManager can call this method to force RecyclerView to run simple animations in the next layout pass, even if there is not any trigger to do so.
Link copied to clipboard
open fun scrollHorizontallyBy(dx: Int, recycler: RecyclerView.Recycler, state: RecyclerView.State): Int
Scroll horizontally by dx pixels in screen coordinates and return the distance traveled.
Link copied to clipboard
Scroll to the specified adapter position.
Link copied to clipboard
open fun scrollVerticallyBy(dy: Int, recycler: RecyclerView.Recycler, state: RecyclerView.State): Int
Scroll vertically by dy pixels in screen coordinates and return the distance traveled.
Link copied to clipboard
Defines whether the measuring pass of layout should use the AutoMeasure mechanism of RecyclerView or if it should be done by the LayoutManager's implementation of onMeasure.
Link copied to clipboard
Sets whether the LayoutManager should be queried for views outside of its viewport while the UI thread is idle between frames.
Link copied to clipboard
Set the measured dimensions of the host RecyclerView.
Sets the measured dimensions from the given bounding box of the children and the measurement specs that were passed into onMeasure.
Link copied to clipboard
Sets whether RecyclerView should use its own measurement cache for the children.
Link copied to clipboard
open fun smoothScrollToPosition(recyclerView: RecyclerView, state: RecyclerView.State, position: Int)
Smooth scroll to the specified adapter position.
Link copied to clipboard
Starts a smooth scroll using the provided SmoothScroller.
Link copied to clipboard
View can be scrapped and recycled again.
Link copied to clipboard
Returns whether this LayoutManager supports "predictive item animations".