GridLayoutManager

public final class GridLayoutManager
extends RecyclerView.LayoutManager

java.lang.Object
   ↳ androidx.recyclerview.widget.RecyclerView.LayoutManager
     ↳ androidx.leanback.widget.GridLayoutManager


A RecyclerView.LayoutManager implementation that lays out items in a grid for leanback VerticalGridView and HorizontalGridView.

Summary

Public constructors

GridLayoutManager()

Public methods

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.

void collectAdjacentPrefetchPositions(int dx, int dy, RecyclerView.State state, RecyclerView.LayoutManager.LayoutPrefetchRegistry layoutPrefetchRegistry)

Gather all positions from the LayoutManager to be prefetched, given specified momentum.

void collectInitialPrefetchPositions(int adapterItemCount, RecyclerView.LayoutManager.LayoutPrefetchRegistry 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.

RecyclerView.LayoutParams generateDefaultLayoutParams()

Create a default LayoutParams object for a child of the RecyclerView.

RecyclerView.LayoutParams generateLayoutParams(Context context, AttributeSet attrs)

Create a LayoutParams object suitable for this LayoutManager from an inflated layout resource.

RecyclerView.LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp)

Create a LayoutParams object suitable for this LayoutManager, copying relevant values from the supplied LayoutParams object if possible.

int getColumnCountForAccessibility(RecyclerView.Recycler recycler, RecyclerView.State state)

Returns the number of columns for accessibility.

int getDecoratedBottom(View child)

Returns the bottom edge of the given child view within its parent, offset by any applied ItemDecorations.

void getDecoratedBoundsWithMargins(View view, Rect outBounds)

Returns the bounds of the view including its decoration and margins.

int getDecoratedLeft(View child)

Returns the left edge of the given child view within its parent, offset by any applied ItemDecorations.

int getDecoratedRight(View child)

Returns the right edge of the given child view within its parent, offset by any applied ItemDecorations.

int getDecoratedTop(View child)

Returns the top edge of the given child view within its parent, offset by any applied ItemDecorations.

int getRowCountForAccessibility(RecyclerView.Recycler recycler, RecyclerView.State state)

Returns the number of rows for accessibility.

void onAdapterChanged(Adapter oldAdapter, Adapter newAdapter)

Called if the RecyclerView this LayoutManager is bound to has a different adapter set via RecyclerView.setAdapter(Adapter) or RecyclerView.swapAdapter(Adapter, boolean).

boolean onAddFocusables(RecyclerView recyclerView, ArrayList<View> views, int direction, int focusableMode)

Called to populate focusable views within the RecyclerView.

void onInitializeAccessibilityNodeInfo(RecyclerView.Recycler recycler, RecyclerView.State state, AccessibilityNodeInfoCompat info)

Called by the AccessibilityDelegate when the information about the current layout should be populated.

void onInitializeAccessibilityNodeInfoForItem(RecyclerView.Recycler recycler, RecyclerView.State state, View host, AccessibilityNodeInfoCompat info)

Called by the AccessibilityDelegate when the accessibility information for a specific item should be populated.

View onInterceptFocusSearch(View focused, int direction)

This method gives a LayoutManager an opportunity to intercept the initial focus search before the default behavior of FocusFinder is used.

void onItemsAdded(RecyclerView recyclerView, int positionStart, int itemCount)

Called when items have been added to the adapter.

void onItemsChanged(RecyclerView recyclerView)

Called in response to a call to RecyclerView.Adapter.notifyDataSetChanged() or RecyclerView.swapAdapter(Adapter, boolean) ()} and signals that the the entire data set has changed.

void onItemsMoved(RecyclerView recyclerView, int fromPosition, int toPosition, int itemCount)

Called when an item is moved withing the adapter.

void onItemsRemoved(RecyclerView recyclerView, int positionStart, int itemCount)

Called when items have been removed from the adapter.

void onItemsUpdated(RecyclerView recyclerView, int positionStart, int itemCount)

Called when items have been changed in the adapter.

void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state)

Lay out all relevant child views from the given adapter.

void onLayoutCompleted(RecyclerView.State state)

Called after a full layout calculation is finished.

void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec, int heightSpec)

Measure the attached RecyclerView.

boolean onRequestChildFocus(RecyclerView parent, RecyclerView.State state, View child, View focused)

Called when a descendant view of the RecyclerView requests focus.

void onRestoreInstanceState(Parcelable state)

Called when the RecyclerView is ready to restore the state based on a previous RecyclerView.

Parcelable onSaveInstanceState()

Called when the LayoutManager should save its state.

boolean performAccessibilityAction(RecyclerView.Recycler recycler, RecyclerView.State state, int action, Bundle args)

Called by AccessibilityDelegate when an action is requested from the RecyclerView.

void removeAndRecycleAllViews(RecyclerView.Recycler recycler)

Removes all views and recycles them using the given recycler.

boolean requestChildRectangleOnScreen(RecyclerView parent, View child, Rect rect, boolean immediate)

Called when a child of the RecyclerView wants a particular rectangle to be positioned onto the screen.

int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State state)

Scroll horizontally by dx pixels in screen coordinates and return the distance traveled.

void scrollToPosition(int position)

Scroll to the specified adapter position.

int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state)

Scroll vertically by dy pixels in screen coordinates and return the distance traveled.

void setOrientation(int orientation)
void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position)

Smooth scroll to the specified adapter position.

void startSmoothScroll(RecyclerView.SmoothScroller smoothScroller)

Starts a smooth scroll using the provided RecyclerView.SmoothScroller.

boolean supportsPredictiveItemAnimations()

Returns whether this LayoutManager supports "predictive item animations".

Inherited methods