LinearLayoutManager

public class LinearLayoutManager
extends RecyclerView.LayoutManager implements ItemTouchHelper.ViewDropHandler, RecyclerView.SmoothScroller.ScrollVectorProvider

java.lang.Object
   ↳ androidx.recyclerview.widget.RecyclerView.LayoutManager
     ↳ androidx.recyclerview.widget.LinearLayoutManager


A RecyclerView.LayoutManager implementation which provides similar functionality to ListView.

Summary

Nested classes

class LinearLayoutManager.LayoutChunkResult

 

Constants

int HORIZONTAL

int INVALID_OFFSET

int VERTICAL

Public constructors

LinearLayoutManager(Context context)

Creates a vertical LinearLayoutManager

LinearLayoutManager(Context context, int orientation, boolean reverseLayout)
LinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Constructor used when layout manager is set in XML by RecyclerView attribute "layoutManager".

Public methods

void assertNotInLayoutOrScroll(String message)

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

boolean canScrollHorizontally()

Query if horizontal scrolling is currently supported.

boolean canScrollVertically()

Query if vertical scrolling is currently supported.

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.

int computeHorizontalScrollExtent(RecyclerView.State state)

Override this method if you want to support scroll bars.

int computeHorizontalScrollOffset(RecyclerView.State state)

Override this method if you want to support scroll bars.

int computeHorizontalScrollRange(RecyclerView.State state)

Override this method if you want to support scroll bars.

PointF computeScrollVectorForPosition(int targetPosition)

Should calculate the vector that points to the direction where the target position can be found.

int computeVerticalScrollExtent(RecyclerView.State state)

Override this method if you want to support scroll bars.

int computeVerticalScrollOffset(RecyclerView.State state)

Override this method if you want to support scroll bars.

int computeVerticalScrollRange(RecyclerView.State state)

Override this method if you want to support scroll bars.

int findFirstCompletelyVisibleItemPosition()

Returns the adapter position of the first fully visible view.

int findFirstVisibleItemPosition()

Returns the adapter position of the first visible view.

int findLastCompletelyVisibleItemPosition()

Returns the adapter position of the last fully visible view.

int findLastVisibleItemPosition()

Returns the adapter position of the last visible view.

View findViewByPosition(int position)

Finds the view which represents the given adapter position.

RecyclerView.LayoutParams generateDefaultLayoutParams()

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

int getInitialPrefetchItemCount()

Gets the number of items to prefetch in collectInitialPrefetchPositions(int, LayoutPrefetchRegistry), which defines how many inner items should be prefetched when this LayoutManager's RecyclerView is nested inside another RecyclerView.

int getOrientation()

Returns the current orientation of the layout.

boolean getRecycleChildrenOnDetach()

Returns whether LayoutManager will recycle its children when it is detached from RecyclerView.

boolean getReverseLayout()

Returns if views are laid out from the opposite direction of the layout.

boolean getStackFromEnd()
boolean isAutoMeasureEnabled()

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(Recycler, State, int, int).

boolean isSmoothScrollbarEnabled()

Returns the current state of the smooth scrollbar feature.

void onDetachedFromWindow(RecyclerView view, RecyclerView.Recycler recycler)

Called when this LayoutManager is detached from its parent RecyclerView or when its parent RecyclerView is detached from its window.

View onFocusSearchFailed(View focused, int direction, RecyclerView.Recycler recycler, RecyclerView.State state)

Called when searching for a focusable view in the given direction has failed for the current content of the RecyclerView.

void onInitializeAccessibilityEvent(AccessibilityEvent event)
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 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.

void prepareForDrop(View view, View target, int x, int y)

Called by the ItemTouchHelper after a View is dropped over another View.

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 the RecyclerView to make the position visible.

void scrollToPositionWithOffset(int position, int offset)

Scroll to the specified adapter position with the given offset from resolved layout start.

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

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

void setInitialPrefetchItemCount(int itemCount)

Sets the number of items to prefetch in collectInitialPrefetchPositions(int, LayoutPrefetchRegistry), which defines how many inner items should be prefetched when this LayoutManager's RecyclerView is nested inside another RecyclerView.

void setOrientation(int orientation)

Sets the orientation of the layout.

void setRecycleChildrenOnDetach(boolean recycleChildrenOnDetach)

Set whether LayoutManager will recycle its children when it is detached from RecyclerView.

void setReverseLayout(boolean reverseLayout)

Used to reverse item traversal and layout order.

void setSmoothScrollbarEnabled(boolean enabled)

When smooth scrollbar is enabled, the position and size of the scrollbar thumb is computed based on the number of visible pixels in the visible items.

void setStackFromEnd(boolean stackFromEnd)

Compatibility support for AbsListView.setStackFromBottom(boolean)

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

Smooth scroll to the specified adapter position.

boolean supportsPredictiveItemAnimations()

Returns whether this LayoutManager supports "predictive item animations".

Protected methods

void calculateExtraLayoutSpace(RecyclerView.State state, int[] extraLayoutSpace)

Calculates the amount of extra space (in pixels) that should be laid out by LinearLayoutManager and stores the result in extraLayoutSpace.

int getExtraLayoutSpace(RecyclerView.State state)

This method is deprecated. Use calculateExtraLayoutSpace(RecyclerView.State, int[]) instead.

boolean isLayoutRTL()

Inherited methods