RecyclerView.LayoutManager

public static abstract class RecyclerView.LayoutManager
extends Object

java.lang.Object
   ↳ androidx.recyclerview.widget.RecyclerView.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.

If the LayoutManager specifies a default constructor or one with the signature (Context, AttributeSet, int, int), RecyclerView will instantiate and set the LayoutManager when being inflated. Most used properties can be then obtained from getProperties(Context, AttributeSet, int, int). In case a LayoutManager specifies both constructors, the non-default constructor will take precedence.

Summary

Nested classes

interface RecyclerView.LayoutManager.LayoutPrefetchRegistry

Interface for LayoutManagers to request items to be prefetched, based on position, with specified distance from viewport, which indicates priority. 

class RecyclerView.LayoutManager.Properties

Some general properties that a LayoutManager may want to use. 

Public constructors

LayoutManager()

Public methods

void addDisappearingView(View child, int index)

To be called only during onLayoutChildren(Recycler, State) 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.

void addDisappearingView(View child)

To be called only during onLayoutChildren(Recycler, State) 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.

void addView(View child, int index)

Add a view to the currently attached RecyclerView if needed.

void addView(View child)

Add a view to the currently attached RecyclerView if needed.

void assertInLayoutOrScroll(String message)

Checks if RecyclerView is in the middle of a layout or scroll and throws an IllegalStateException if it is not.

void assertNotInLayoutOrScroll(String message)

Checks if RecyclerView is in the middle of a layout or scroll and throws an IllegalStateException if it is.

void attachView(View child)

Reattach a previously detached view.

void attachView(View child, int index, RecyclerView.LayoutParams lp)

Reattach a previously detached view.

void attachView(View child, int index)

Reattach a previously detached view.

void calculateItemDecorationsForChild(View child, Rect outRect)

Calculates the item decor insets applied to the given child and updates the provided Rect instance with the inset values.

boolean canScrollHorizontally()

Query if horizontal scrolling is currently supported.

boolean canScrollVertically()

Query if vertical scrolling is currently supported.

boolean checkLayoutParams(RecyclerView.LayoutParams lp)

Determines the validity of the supplied LayoutParams object.

static int chooseSize(int spec, int desired, int min)

Chooses a size from the given specs and parameters that is closest to the desired size and also complies with the spec.

void collectAdjacentPrefetchP