RecyclerView

open class RecyclerView : ViewGroup
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ androidx.recyclerview.widget.RecyclerView

A flexible view for providing a limited window into a large data set. Glossary of terms:

  • Adapter: A subclass of Adapter responsible for providing views that represent items in a data set.
  • Position: The position of a data item within an Adapter.
  • Index: The index of an attached child view as used in a call to ViewGroup#getChildAt. Contrast with Position.
  • Binding: The process of preparing a child view to display data corresponding to a position within the adapter.
  • Recycle (view): A view previously used to display data for a specific adapter position may be placed in a cache for later reuse to display the same type of data again later. This can drastically improve performance by skipping initial layout inflation or construction.
  • Scrap (view): A child view that has entered into a temporarily detached state during layout. Scrap views may be reused without becoming fully detached from the parent RecyclerView, either unmodified if no rebinding is required or modified by the adapter if the view was considered dirty.
  • Dirty (view): A child view that must be rebound by the adapter before being displayed.
Positions in RecyclerView:

RecyclerView introduces an additional level of abstraction between the Adapter and LayoutManager to be able to detect data set changes in batches during a layout calculation. This saves LayoutManager from tracking adapter changes to calculate animations. It also helps with performance because all view bindings happen at the same time and unnecessary bindings are avoided.

For this reason, there are two types of position related methods in RecyclerView:

  • layout position: Position of an item in the latest layout calculation. This is the position from the LayoutManager's perspective.
  • adapter position: Position of an item in the adapter. This is the position from the Adapter's perspective.

These two positions are the same except the time between dispatching adapter.notify* events and calculating the updated layout.

Methods that return or receive *LayoutPosition* use position as of the latest layout calculation (e.g. ViewHolder#getLayoutPosition(), #findViewHolderForLayoutPosition(int)). These positions include all changes until the last layout calculation. You can rely on these positions to be consistent with what user is currently seeing on the screen. For example, if you have a list of items on the screen and user asks for the 5th element, you should use these methods as they'll match what user is seeing.

The other set of position related methods are in the form of *AdapterPosition*. (e.g. ViewHolder#getAdapterPosition(), #findViewHolderForAdapterPosition(int)) You should use these methods when you need to work with up-to-date adapter positions even if they may not have been reflected to layout yet. For example, if you want to access the item in the adapter on a ViewHolder click, you should use ViewHolder#getAdapterPosition(). Beware that these methods may not be able to calculate adapter positions if Adapter#notifyDataSetChanged() has been called and new layout has not yet been calculated. For this reasons, you should carefully handle #NO_POSITION or null results from these methods.

When writing a LayoutManager you almost always want to use layout positions whereas when writing an Adapter, you probably want to use adapter positions.

Summary

Nested classes
abstract

Base class for an Adapter

abstract

Observer base class for watching changes to an Adapter.

abstract

A callback interface that can be used to alter the drawing order of RecyclerView children.

open

EdgeEffectFactory lets you customize the over-scroll edge effect for RecyclerViews.

abstract

This class defines the animations that take place on items as changes are made to the adapter.

abstract

An ItemDecoration allows the application to add a special drawing and layout offset to specific item views from the adapter's data set.

abstract

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.

open

LayoutParams subclass for children of RecyclerView.

abstract

A Listener interface that can be attached to a RecylcerView to get notified whenever a ViewHolder is attached to or detached from RecyclerView.

abstract

This class defines the behavior of fling if the developer wishes to handle it.

abstract

An OnItemTouchListener allows the application to intercept touch events in progress at the view hierarchy level of the RecyclerView before those touch events are considered for RecyclerView's own scrolling behavior.

abstract

An OnScrollListener can be added to a RecyclerView to receive messages when a scrolling event has occurred on that RecyclerView.

open

RecycledViewPool lets you share Views between multiple RecyclerViews.

A Recycler is responsible for managing scrapped or detached item views for reuse.

abstract

A RecyclerListener can be set on a RecyclerView to receive messages whenever a view is recycled.

open

An implementation of RecyclerView.OnItemTouchListener that has empty method bodies and default return values.

abstract

Base class for smooth scrolling.

open

Contains useful information about the current RecyclerView state like target scroll position or view focus.

abstract

ViewCacheExtension is a helper class to provide an additional layer of view caching that can be controlled by the developer.

abstract

A ViewHolder describes an item view and metadata about its place within the RecyclerView.

Constants
static Int

static Int

static Long

static Int

static Int

The RecyclerView is currently being dragged by outside input such as user touch input.

static Int

The RecyclerView is not currently scrolling.

static Int

The RecyclerView is currently animating to a final position while not under outside control.

static Int

Constant for use with #setScrollingTouchSlop(int).

static Int

Constant for use with #setScrollingTouchSlop(int).

static Int

Public constructors
<init>(context: Context)

<init>(context: Context, attrs: AttributeSet?)

<init>(context: Context, attrs: AttributeSet?, defStyle: Int)

Public methods
open RecyclerView.ViewHolder!

open Unit

Register a listener that will be notified whenever a child view is recycled.

open Unit
setClipToPadding(clipToPadding: Boolean)

open Long

Return the stable item id that the given child view corresponds to.

open Boolean

open Int

Returns the number of ItemDecoration currently added to this RecyclerView.

open Boolean

Returns true if the RecyclerView should attempt to preserve currently focused Adapter Item's focus even if the View representing the Item is replaced during a layout calculation.

open Unit

Recycled view pools allow multiple RecyclerViews to share a common pool of scrap views.

open Unit

Offset the bounds of all child views by dx pixels.

open Boolean

Returns whether this RecyclerView will clip its children to its padding, and resize (but not clip) any EdgeEffect to the padded region, if padding is present.

open Int

Return the offset of the RecyclerView's text baseline from the its top boundary.

open RecyclerView.ItemDecoration

Returns an ItemDecoration previously added to this RecyclerView.

open Unit
scrollBy(x: Int, y: Int)

open Unit

Remove a listener that was notified of any changes in scroll state or position.

open Unit

Remove an OnItemTouchListener.

open Unit

Removes all listeners that were added via #addOnChildAttachStateChangeListener(OnChildAttachStateChangeListener).

open Unit

Called when the scroll state of this RecyclerView changes.

open Boolean

Returns true if RecyclerView is currently running some animations.

open Unit
onScrolled(dx: Int, dy: Int)

Called when the scroll position of this RecyclerView changes.

open View!
focusSearch(focused: View!, direction: Int)

Since RecyclerView is a collection ViewGroup that includes virtual children (items that are in the Adapter but not visible in the UI), it employs a more involved focus search strategy that differs from other ViewGroups.

open RecyclerView.ItemAnimator?

Gets the current ItemAnimator for this RecyclerView.

open Unit

Sets the accessibility delegate compatibility implementation used by RecyclerView.

open Unit

open Boolean

open RecyclerView.LayoutManager?

Return the LayoutManager currently responsible for layout policy for this RecyclerView.

open Int

Return the adapter position of the given child view as of the latest completed layout pass.

open Unit

Set the LayoutManager that this RecyclerView will use.

open Boolean
dispatchNestedPreFling(velocityX: Float, velocityY: Float)

open Boolean

open Boolean
startNestedScroll(axes: Int, type: Int)

open Unit
smoothScrollBy(dx: Int, dy: Int)

Animate a scroll by the given amount of pixels along either axis.

open Unit
smoothScrollBy(dx: Int, dy: Int, interpolator: Interpolator?)

Animate a scroll by the given amount of pixels along either axis.

open Int

Return the current scrolling state of the RecyclerView.

open Unit

Called when an item view is detached from this RecyclerView.

open RecyclerView.ViewHolder?

Returns the ViewHolder that contains the given view.

open Unit
setPreserveFocusAfterLayout(preserveFocusAfterLayout: Boolean)

Set whether the RecyclerView should try to keep the same Item focused after a layout calculation or not.

open Unit

Register a listener that will be notified whenever a child view is attached to or detached from RecyclerView.

open RecyclerView.Adapter<RecyclerView.ViewHolder!>?

Retrieves the previously set adapter or null if no adapter is set.

open Boolean
drawChild(canvas: Canvas!, child: View!, drawingTime: Long)

open Boolean
fling(velocityX: Int, velocityY: Int)

Begin a standard fling with an initial velocity along each axis in pixels per second.

open Unit

Invalidates all ItemDecorations.

open Unit
setScrollingTouchSlop(slopConstant: Int)

Configure the scrolling touch slop for a specific use case.

open Boolean

Returns true if layout and scroll are frozen.

open Unit

Stop any current scroll in progress, such as one started by #smoothScrollBy(int, int), #fling(int, int) or a touch-initiated fling.

open Unit
scrollTo(x: Int, y: Int)

open Int

Returns the minimum velocity to start a fling.

open Unit
scrollToPosition(position: Int)

Convenience method to scroll to a certain position.

open Unit

Add an OnItemTouchListener to intercept touch events before they are dispatched to child views or this view's standard scrolling behavior.

open Unit

Removes the provided listener from child attached state listeners list.

open Unit

Set a OnFlingListener for this RecyclerView.

open Unit
addFocusables(views: ArrayList<View!>!, direction: Int, focusableMode: Int)

open Unit

Sets the ChildDrawingOrderCallback to be used for drawing children.

open Boolean

open Unit

Sets the ItemAnimator that will handle animations involving changes to the items in this RecyclerView.

open Int

Return the adapter position that the given child view corresponds to.

open Boolean
dispatchNestedPreScroll(dx: Int, dy: Int, consumed: IntArray!, offsetInWindow: IntArray!)

open Boolean
dispatchNestedPreScroll(dx: Int, dy: Int, consumed: IntArray!, offsetInWindow: IntArray!, type: Int)

open Unit

Remove all secondary listener that were notified of any changes in scroll state or position.

open Int

Compute the horizontal offset of the horizontal scrollbar's thumb within the horizontal range.

open Unit

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

open Boolean

Returns true if RecyclerView is attached to window.

open Unit

open Unit

open Boolean

open View?

Find the topmost view under the given point.

open View?

Traverses the ancestors of the given view and returns the item view that contains it and also a direct child of the RecyclerView.

open Boolean

open Boolean

open Boolean

open RecyclerView.RecycledViewPool

Retrieve this RecyclerView's RecycledViewPool.

open RecyclerView.EdgeEffectFactory

Retrieves the previously set EdgeEffectFactory or the default factory if nothing was set.

open Unit

open Int

Compute the vertical range that the vertical scrollbar represents.

open Int

Compute the horizontal range that the horizontal scrollbar represents.

open RecyclerView.ViewHolder!

Return the ViewHolder for the item with the given id.

open Boolean

Returns whether there are pending adapter updates which are not yet applied to the layout.

open Unit
setHasFixedSize(hasFixedSize: Boolean)

RecyclerView can perform several optimizations if it can know in advance that RecyclerView's size is not affected by the adapter contents.

open Unit

Add a listener that will be notified of any changes in scroll state or position.

open Unit
requestChildFocus(child: View!, focused: View!)

open RecyclerViewAccessibilityDelegate?

Returns the accessibility delegate compatibility implementation used by the RecyclerView.

open Int

Compute the horizontal extent of the horizontal scrollbar's thumb within the horizontal range.

open Unit

Add an ItemDecoration to this RecyclerView.

open Unit

Add an ItemDecoration to this RecyclerView.

open Int

Compute the vertical offset of the vertical scrollbar's thumb within the vertical range.

open Unit

Called when an item view is attached to this RecyclerView.

open Unit

Set a EdgeEffectFactory for this RecyclerView.

open Unit

Remove an ItemDecoration from this RecyclerView.

open Boolean
dispatchNestedScroll(dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, offsetInWindow: IntArray!)

open Boolean
dispatchNestedScroll(dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, offsetInWindow: IntArray!, type: Int)

open Unit

Set a new adapter to provide child views on demand.

open Boolean
requestChildRectangleOnScreen(child: View!, rect: Rect!, immediate: Boolean)

open RecyclerView.OnFlingListener?

Get the current OnFlingListener from this RecyclerView.

open Int

Returns the maximum fling velocity used by this RecyclerView.

open Int

open LayoutParams!

open Unit

open Boolean

Returns whether RecyclerView is currently computing a layout.

open Unit

Starts a smooth scroll to an adapter position.

open RecyclerView.ViewHolder!

Return the ViewHolder for the item in the given position of the data set.

open Unit
draw(c: Canvas!)

open Boolean
dispatchNestedFling(velocityX: Float, velocityY: Float, consumed: Boolean)

open RecyclerView.ViewHolder!

Retrieve the ViewHolder for the given child view.

open Unit

Offset the bounds of all child views by dy pixels.

open Unit

open RecyclerView.ViewHolder!

Return the ViewHolder for the item in the given position of the data set as of the latest layout pass.

open Int

Compute the vertical extent of the vertical scrollbar's thumb within the vertical range.

open Unit

Enable or disable layout and scroll.

open Unit

Removes the ItemDecoration associated with the supplied index position.

open Unit
swapAdapter(adapter: RecyclerView.Adapter<RecyclerView.ViewHolder!>?, removeAndRecycleExistingViews: Boolean)

Swaps the current adapter with the provided one.

open Unit

Sets a new ViewCacheExtension to be used by the Recycler.

open Unit

open Unit

Set the number of offscreen views to retain before adding them to the potentially shared recycled view pool.

open Unit

Set a listener that will be notified of any changes in scroll state or position.

Protected methods
open Int
getChildDrawingOrder(childCount: Int, i: Int)

open Unit

Override to prevent thawing of any views created by the adapter.

open Unit

Override to prevent freezing of any views created by the adapter.

open Unit

open Boolean
onRequestFocusInDescendants(direction: Int, previouslyFocusedRect: Rect!)

open Unit
onMeasure(widthSpec: Int, heightSpec: Int)

open LayoutParams!

open Unit

open Unit

open Boolean

open Unit
onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int)

open Parcelable!

open Unit
onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int)

open LayoutParams!

open Unit
removeDetachedView(child: View!, animate: Boolean)

Constants

HORIZONTAL

static val HORIZONTAL: Int
Value: 0

INVALID_TYPE

static val INVALID_TYPE: Int
Value: -1

NO_ID

static val NO_ID: Long
Value: -1L

NO_POSITION

static val NO_POSITION: Int
Value: -1

SCROLL_STATE_DRAGGING

static val SCROLL_STATE_DRAGGING: Int

The RecyclerView is currently being dragged by outside input such as user touch input.

Value: 1

SCROLL_STATE_IDLE

static val SCROLL_STATE_IDLE: Int

The RecyclerView is not currently scrolling.

Value: 0

SCROLL_STATE_SETTLING

static val SCROLL_STATE_SETTLING: Int

The RecyclerView is currently animating to a final position while not under outside control.

Value: 2

TOUCH_SLOP_DEFAULT

static val TOUCH_SLOP_DEFAULT: Int

Constant for use with #setScrollingTouchSlop(int). Indicates that the RecyclerView should use the standard touch slop for smooth, continuous scrolling.

Value: 0

TOUCH_SLOP_PAGING

static val TOUCH_SLOP_PAGING: Int

Constant for use with #setScrollingTouchSlop(int). Indicates that the RecyclerView should use the standard touch slop for scrolling widgets that snap to a page or other coarse-grained barrier.

Value: 1

VERTICAL

static val VERTICAL: Int
Value: 1

Public constructors

<init>

RecyclerView(context: Context)

<init>

RecyclerView(context: Context, attrs: AttributeSet?)

<init>

RecyclerView(context: Context, attrs: AttributeSet?, defStyle: Int)

Public methods

findViewHolderForPosition

open fun findViewHolderForPosition(position: Int): RecyclerView.ViewHolder!

setRecyclerListener

open fun setRecyclerListener(listener: RecyclerView.RecyclerListener?): Unit

Register a listener that will be notified whenever a child view is recycled.

This listener will be called when a LayoutManager or the RecyclerView decides that a child view is no longer needed. If an application associates expensive or heavyweight data with item views, this may be a good place to release or free those resources.

Parameters
listener RecyclerView.RecyclerListener?: Listener to register, or null to clear

setClipToPadding

open fun setClipToPadding(clipToPadding: Boolean): Unit

getChildItemId

open fun getChildItemId(child: View): Long

Return the stable item id that the given child view corresponds to.

Parameters
child View: Child View to query
Return
Long: Item id corresponding to the given view or #NO_ID

onTouchEvent

open fun onTouchEvent(e: MotionEvent!): Boolean

getItemDecorationCount

open fun getItemDecorationCount(): Int

Returns the number of ItemDecoration currently added to this RecyclerView.

Return
Int: number of ItemDecorations currently added added to this RecyclerView.

getPreserveFocusAfterLayout

open fun getPreserveFocusAfterLayout(): Boolean

Returns true if the RecyclerView should attempt to preserve currently focused Adapter Item's focus even if the View representing the Item is replaced during a layout calculation.

By default, this value is true.

Return
Boolean: True if the RecyclerView will try to preserve focused Item after a layout if it loses focus.

setRecycledViewPool

open fun setRecycledViewPool(pool: RecyclerView.RecycledViewPool?): Unit

Recycled view pools allow multiple RecyclerViews to share a common pool of scrap views. This can be useful if you have multiple RecyclerViews with adapters that use the same view types, for example if you have several data sets with the same kinds of item views displayed by a ViewPager.

Parameters
pool RecyclerView.RecycledViewPool?: Pool to set. If this parameter is null a new pool will be created and used.

offsetChildrenHorizontal

open fun offsetChildrenHorizontal(dx: Int): Unit

Offset the bounds of all child views by dx pixels. Useful for implementing simple scrolling in LayoutManagers.

Parameters
dx Int: Horizontal pixel offset to apply to the bounds of all child views

getClipToPadding

open fun getClipToPadding(): Boolean

Returns whether this RecyclerView will clip its children to its padding, and resize (but not clip) any EdgeEffect to the padded region, if padding is present.

By default, children are clipped to the padding of their parent RecyclerView. This clipping behavior is only enabled if padding is non-zero.

Return
Boolean: true if this RecyclerView clips children to its padding and resizes (but doesn't clip) any EdgeEffect to the padded region, false otherwise.

getBaseline

open fun getBaseline(): Int

Return the offset of the RecyclerView's text baseline from the its top boundary. If the LayoutManager of this RecyclerView does not support baseline alignment, this method returns -1.

Return
Int: the offset of the baseline within the RecyclerView's bounds or -1 if baseline alignment is not supported

getItemDecorationAt

open fun getItemDecorationAt(index: Int): RecyclerView.ItemDecoration

Returns an ItemDecoration previously added to this RecyclerView.

Parameters
index Int: The index position of the desired ItemDecoration.
Return
RecyclerView.ItemDecoration: the ItemDecoration at index position
Exceptions
IndexOutOfBoundsException on invalid index

scrollBy

open fun scrollBy(x: Int, y: Int): Unit

removeOnScrollListener

open fun removeOnScrollListener(listener: RecyclerView.OnScrollListener): Unit

Remove a listener that was notified of any changes in scroll state or position.

Parameters
listener RecyclerView.OnScrollListener: listener to set or null to clear

removeOnItemTouchListener

open fun removeOnItemTouchListener(listener: RecyclerView.OnItemTouchListener): Unit

Remove an OnItemTouchListener. It will no longer be able to intercept touch events.

Parameters
listener RecyclerView.OnItemTouchListener: Listener to remove

clearOnChildAttachStateChangeListeners

open fun clearOnChildAttachStateChangeListeners(): Unit

Removes all listeners that were added via #addOnChildAttachStateChangeListener(OnChildAttachStateChangeListener).

onScrollStateChanged

open fun onScrollStateChanged(state: Int): Unit

Called when the scroll state of this RecyclerView changes. Subclasses should use this method to respond to state changes instead of an explicit listener.

This method will always be invoked before listeners, but after the LayoutManager responds to the scroll state change.

Parameters
state Int: the new scroll state, one of #SCROLL_STATE_IDLE, #SCROLL_STATE_DRAGGING or #SCROLL_STATE_SETTLING

isAnimating

open fun isAnimating(): Boolean

Returns true if RecyclerView is currently running some animations.

If you want to be notified when animations are finished, use ItemAnimator#isRunning(ItemAnimator.ItemAnimatorFinishedListener).

Return
Boolean: True if there are some item animations currently running or waiting to be started.

onScrolled

open fun onScrolled(dx: Int, dy: Int): Unit

Called when the scroll position of this RecyclerView changes. Subclasses should use this method to respond to scrolling within the adapter's data set instead of an explicit listener.

This method will always be invoked before listeners. If a subclass needs to perform any additional upkeep or bookkeeping after scrolling but before listeners run, this is a good place to do so.

This differs from View#onScrollChanged(int, int, int, int) in that it receives the distance scrolled in either direction within the adapter's data set instead of absolute scroll coordinates. Since RecyclerView cannot compute the absolute scroll position from any arbitrary point in the data set, onScrollChanged will always receive the current View#getScrollX() and View#getScrollY() values which do not correspond to the data set scroll position. However, some subclasses may choose to use these fields as special offsets.

Parameters
dx Int: horizontal distance scrolled in pixels
dy Int: vertical distance scrolled in pixels

focusSearch

open fun focusSearch(focused: View!, direction: Int): View!

Since RecyclerView is a collection ViewGroup that includes virtual children (items that are in the Adapter but not visible in the UI), it employs a more involved focus search strategy that differs from other ViewGroups.

It first does a focus search within the RecyclerView. If this search finds a View that is in the focus direction with respect to the currently focused View, RecyclerView returns that child as the next focus target. When it cannot find such child, it calls LayoutManager#onFocusSearchFailed(View, int, Recycler, State) to layout more Views in the focus search direction. If LayoutManager adds a View that matches the focus search criteria, it will be returned as the focus search result. Otherwise, RecyclerView will call parent to handle the focus search like a regular ViewGroup.

When the direction is View#FOCUS_FORWARD or View#FOCUS_BACKWARD, a View that is not in the focus direction is still valid focus target which may not be the desired behavior if the Adapter has more children in the focus direction. To handle this case, RecyclerView converts the focus direction to an absolute direction and makes a preliminary focus search in that direction. If there are no Views to gain focus, it will call LayoutManager#onFocusSearchFailed(View, int, Recycler, State) before running a focus search with the original (relative) direction. This allows RecyclerView to provide better candidates to the focus search while still allowing the view system to take focus from the RecyclerView and give it to a more suitable child if such child exists.

Parameters
focused View!: The view that currently has focus
direction View!: One of View#FOCUS_UP, View#FOCUS_DOWN, View#FOCUS_LEFT, View#FOCUS_RIGHT, View#FOCUS_FORWARD, View#FOCUS_BACKWARD or 0 for not applicable.
Return
View!: A new View that can be the next focus after the focused View

getItemAnimator

open fun getItemAnimator(): RecyclerView.ItemAnimator?

Gets the current ItemAnimator for this RecyclerView. A null return value indicates that there is no animator and that item changes will happen without any animations. By default, RecyclerView instantiates and uses an instance of DefaultItemAnimator.

Return
RecyclerView.ItemAnimator?: ItemAnimator The current ItemAnimator. If null, no animations will occur when changes occur to the items in this RecyclerView.

setAccessibilityDelegateCompat

open fun setAccessibilityDelegateCompat(accessibilityDelegate: RecyclerViewAccessibilityDelegate?): Unit

Sets the accessibility delegate compatibility implementation used by RecyclerView.

Parameters
accessibilityDelegate RecyclerViewAccessibilityDelegate?: The accessibility delegate to be used by RecyclerView.

setNestedScrollingEnabled

open fun setNestedScrollingEnabled(enabled: Boolean): Unit

hasFixedSize

open fun hasFixedSize(): Boolean
Return
Boolean: true if the app has specified that changes in adapter content cannot change the size of the RecyclerView itself.

getLayoutManager

open fun getLayoutManager(): RecyclerView.LayoutManager?

Return the LayoutManager currently responsible for layout policy for this RecyclerView.

Return
RecyclerView.LayoutManager?: The currently bound LayoutManager

getChildLayoutPosition

open fun getChildLayoutPosition(child: View): Int

Return the adapter position of the given child view as of the latest completed layout pass.

This position may not be equal to Item's adapter position if there are pending changes in the adapter which have not been reflected to the layout yet.

Parameters
child View: Child View to query
Return
Int: Adapter position of the given View as of last layout pass or #NO_POSITION if the View is representing a removed item.

setLayoutManager

open fun setLayoutManager(layout: RecyclerView.LayoutManager?): Unit

Set the LayoutManager that this RecyclerView will use.

In contrast to other adapter-backed views such as android.widget.ListView or android.widget.GridView, RecyclerView allows client code to provide custom layout arrangements for child views. These arrangements are controlled by the LayoutManager. A LayoutManager must be provided for RecyclerView to function.

Several default strategies are provided for common uses such as lists and grids.

Parameters
layout RecyclerView.LayoutManager?: LayoutManager to use

dispatchNestedPreFling

open fun dispatchNestedPreFling(velocityX: Float, velocityY: Float): Boolean

startNestedScroll

open fun startNestedScroll(axes: Int): Boolean

startNestedScroll

open fun startNestedScroll(axes: Int, type: Int): Boolean

smoothScrollBy

open fun smoothScrollBy(dx: Int, dy: Int): Unit

Animate a scroll by the given amount of pixels along either axis.

Parameters
dx Int: Pixels to scroll horizontally
dy Int: Pixels to scroll vertically

smoothScrollBy

open fun smoothScrollBy(dx: Int, dy: Int, interpolator: Interpolator?): Unit

Animate a scroll by the given amount of pixels along either axis.

Parameters
dx Int: Pixels to scroll horizontally
dy Int: Pixels to scroll vertically
interpolator Int: Interpolator to be used for scrolling. If it is null, RecyclerView is going to use the default interpolator.

getScrollState

open fun getScrollState(): Int

Return the current scrolling state of the RecyclerView.

Return
Int: #SCROLL_STATE_IDLE, #SCROLL_STATE_DRAGGING or #SCROLL_STATE_SETTLING

onChildDetachedFromWindow

open fun onChildDetachedFromWindow(child: View): Unit

Called when an item view is detached from this RecyclerView.

Subclasses of RecyclerView may want to perform extra bookkeeping or modifications of child views as they become detached. This will be called as a LayoutManager fully detaches the child view from the parent and its window.

Parameters
child View: Child view that is now detached from this RecyclerView and its associated window

findContainingViewHolder

open fun findContainingViewHolder(view: View): RecyclerView.ViewHolder?

Returns the ViewHolder that contains the given view.

Parameters
view View: The view that is a descendant of the RecyclerView.
Return
RecyclerView.ViewHolder?: The ViewHolder that contains the given view or null if the provided view is not a descendant of this RecyclerView.

setPreserveFocusAfterLayout

open fun setPreserveFocusAfterLayout(preserveFocusAfterLayout: Boolean): Unit

Set whether the RecyclerView should try to keep the same Item focused after a layout calculation or not.

Usually, LayoutManagers keep focused views visible before and after layout but sometimes, views may lose focus during a layout calculation as their state changes or they are replaced with another view due to type change or animation. In these cases, RecyclerView can request focus on the new view automatically.

Parameters
preserveFocusAfterLayout Boolean: Whether RecyclerView should preserve focused Item during a layout calculations. Defaults to true.

addOnChildAttachStateChangeListener

open fun addOnChildAttachStateChangeListener(listener: RecyclerView.OnChildAttachStateChangeListener): Unit

Register a listener that will be notified whenever a child view is attached to or detached from RecyclerView.

This listener will be called when a LayoutManager or the RecyclerView decides that a child view is no longer needed. If an application associates expensive or heavyweight data with item views, this may be a good place to release or free those resources.

Parameters
listener RecyclerView.OnChildAttachStateChangeListener: Listener to register

getAdapter

open fun getAdapter(): RecyclerView.Adapter<RecyclerView.ViewHolder!>?

Retrieves the previously set adapter or null if no adapter is set.

Return
RecyclerView.Adapter<RecyclerView.ViewHolder!>?: The previously set adapter

drawChild

open fun drawChild(canvas: Canvas!, child: View!, drawingTime: Long): Boolean

fling

open fun fling(velocityX: Int, velocityY: Int): Boolean

Begin a standard fling with an initial velocity along each axis in pixels per second. If the velocity given is below the system-defined minimum this method will return false and no fling will occur.

Parameters
velocityX Int: Initial horizontal velocity in pixels per second
velocityY Int: Initial vertical velocity in pixels per second
Return
Boolean: true if the fling was started, false if the velocity was too low to fling or LayoutManager does not support scrolling in the axis fling is issued.

invalidateItemDecorations

open fun invalidateItemDecorations(): Unit

Invalidates all ItemDecorations. If RecyclerView has item decorations, calling this method will trigger a #requestLayout() call.

setScrollingTouchSlop

open fun setScrollingTouchSlop(slopConstant: Int): Unit

Configure the scrolling touch slop for a specific use case. Set up the RecyclerView's scrolling motion threshold based on common usages. Valid arguments are #TOUCH_SLOP_DEFAULT and #TOUCH_SLOP_PAGING.

Parameters
slopConstant Int: One of the TOUCH_SLOP_ constants representing the intended usage of this RecyclerView

isLayoutFrozen

open fun isLayoutFrozen(): Boolean

Returns true if layout and scroll are frozen.

Return
Boolean: true if layout and scroll are frozen

stopScroll

open fun stopScroll(): Unit

Stop any current scroll in progress, such as one started by #smoothScrollBy(int, int), #fling(int, int) or a touch-initiated fling.

scrollTo

open fun scrollTo(x: Int, y: Int): Unit

getMinFlingVelocity

open fun getMinFlingVelocity(): Int

Returns the minimum velocity to start a fling.

Return
Int: The minimum velocity to start a fling

scrollToPosition

open fun scrollToPosition(position: Int): Unit

Convenience method to scroll to a certain position. RecyclerView does not implement scrolling logic, rather forwards the call to RecyclerView.LayoutManager#scrollToPosition(int)

Parameters
position Int: Scroll to this adapter position

addOnItemTouchListener

open fun addOnItemTouchListener(listener: RecyclerView.OnItemTouchListener): Unit

Add an OnItemTouchListener to intercept touch events before they are dispatched to child views or this view's standard scrolling behavior.

Client code may use listeners to implement item manipulation behavior. Once a listener returns true from OnItemTouchListener#onInterceptTouchEvent(RecyclerView, MotionEvent) its OnItemTouchListener#onTouchEvent(RecyclerView, MotionEvent) method will be called for each incoming MotionEvent until the end of the gesture.

Parameters
listener RecyclerView.OnItemTouchListener: Listener to add

removeOnChildAttachStateChangeListener

open fun removeOnChildAttachStateChangeListener(listener: RecyclerView.OnChildAttachStateChangeListener): Unit

Removes the provided listener from child attached state listeners list.

Parameters
listener RecyclerView.OnChildAttachStateChangeListener: Listener to unregister

setOnFlingListener

open fun setOnFlingListener(onFlingListener: RecyclerView.OnFlingListener?): Unit

Set a OnFlingListener for this RecyclerView.

If the OnFlingListener is set then it will receive calls to #fling(int,int) and will be able to intercept them.

Parameters
onFlingListener RecyclerView.OnFlingListener?: The OnFlingListener instance.

addFocusables

open fun addFocusables(views: ArrayList<View!>!, direction: Int, focusableMode: Int): Unit

setChildDrawingOrderCallback

open fun setChildDrawingOrderCallback(childDrawingOrderCallback: RecyclerView.ChildDrawingOrderCallback?): Unit

Sets the ChildDrawingOrderCallback to be used for drawing children.

See ViewGroup#getChildDrawingOrder(int, int) for details. Calling this method will always call ViewGroup#setChildrenDrawingOrderEnabled(boolean). The parameter will be true if childDrawingOrderCallback is not null, false otherwise.

Note that child drawing order may be overridden by View's elevation.

Parameters
childDrawingOrderCallback RecyclerView.ChildDrawingOrderCallback?: The ChildDrawingOrderCallback to be used by the drawing system.

isNestedScrollingEnabled

open fun isNestedScrollingEnabled(): Boolean

setItemAnimator

open fun setItemAnimator(animator: RecyclerView.ItemAnimator?): Unit

Sets the ItemAnimator that will handle animations involving changes to the items in this RecyclerView. By default, RecyclerView instantiates and uses an instance of DefaultItemAnimator. Whether item animations are enabled for the RecyclerView depends on the ItemAnimator and whether the LayoutManager supports item animations.

Parameters
animator RecyclerView.ItemAnimator?: The ItemAnimator being set. If null, no animations will occur when changes occur to the items in this RecyclerView.

getChildAdapterPosition

open fun getChildAdapterPosition(child: View): Int

Return the adapter position that the given child view corresponds to.

Parameters
child View: Child View to query
Return
Int: Adapter position corresponding to the given view or #NO_POSITION

dispatchNestedPreScroll

open fun dispatchNestedPreScroll(dx: Int, dy: Int, consumed: IntArray!, offsetInWindow: IntArray!): Boolean

dispatchNestedPreScroll

open fun dispatchNestedPreScroll(dx: Int, dy: Int, consumed: IntArray!, offsetInWindow: IntArray!, type: Int): Boolean

clearOnScrollListeners

open fun clearOnScrollListeners(): Unit

Remove all secondary listener that were notified of any changes in scroll state or position.

computeHorizontalScrollOffset

open fun computeHorizontalScrollOffset(): Int

Compute the horizontal offset of the horizontal scrollbar's thumb within the horizontal range. This value is used to compute the length of the thumb within the scrollbar's track.

The range is expressed in arbitrary units that must be the same as the units used by #computeHorizontalScrollRange() and #computeHorizontalScrollExtent().

Default implementation returns 0.

If you want to support scroll bars, override RecyclerView.LayoutManager#computeHorizontalScrollOffset(RecyclerView.State) in your LayoutManager.

Return
Int: The horizontal offset of the scrollbar's thumb

getDecoratedBoundsWithMargins

open fun getDecoratedBoundsWithMargins(view: View, outBounds: Rect): Unit

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

Parameters
view View: The view element to check
outBounds View: A rect that will receive the bounds of the element including its decoration and margins.

isAttachedToWindow

open fun isAttachedToWindow(): Boolean

Returns true if RecyclerView is attached to window.

stopNestedScroll

open fun stopNestedScroll(): Unit

stopNestedScroll

open fun stopNestedScroll(type: Int): Unit

onGenericMotionEvent

open fun onGenericMotionEvent(event: MotionEvent!): Boolean

findChildViewUnder

open fun findChildViewUnder(x: Float, y: Float): View?

Find the topmost view under the given point.

Parameters
x Float: Horizontal position in pixels to search
y Float: Vertical position in pixels to search
Return
View?: The child view under (x, y) or null if no matching child is found

findContainingItemView

open fun findContainingItemView(view: View): View?

Traverses the ancestors of the given view and returns the item view that contains it and also a direct child of the RecyclerView. This returned view can be used to get the ViewHolder by calling #getChildViewHolder(View).

Parameters
view View: The view that is a descendant of the RecyclerView.
Return
View?: The direct child of the RecyclerView which contains the given view or null if the provided view is not a descendant of this RecyclerView.

onInterceptTouchEvent

open fun onInterceptTouchEvent(e: MotionEvent!): Boolean

hasNestedScrollingParent

open fun hasNestedScrollingParent(): Boolean

hasNestedScrollingParent

open fun hasNestedScrollingParent(type: Int): Boolean

getRecycledViewPool

open fun getRecycledViewPool(): RecyclerView.RecycledViewPool

Retrieve this RecyclerView's RecycledViewPool. This method will never return null; if no pool is set for this view a new one will be created. See setRecycledViewPool for more information.

Return
RecyclerView.RecycledViewPool: The pool used to store recycled item views for reuse.

getEdgeEffectFactory

open fun getEdgeEffectFactory(): RecyclerView.EdgeEffectFactory

Retrieves the previously set EdgeEffectFactory or the default factory if nothing was set.

Return
RecyclerView.EdgeEffectFactory: The previously set EdgeEffectFactory

sendAccessibilityEventUnchecked

open fun sendAccessibilityEventUnchecked(event: AccessibilityEvent!): Unit

computeVerticalScrollRange

open fun computeVerticalScrollRange(): Int

Compute the vertical range that the vertical scrollbar represents.

The range is expressed in arbitrary units that must be the same as the units used by #computeVerticalScrollExtent() and #computeVerticalScrollOffset().

Default implementation returns 0.

If you want to support scroll bars, override RecyclerView.LayoutManager#computeVerticalScrollRange(RecyclerView.State) in your LayoutManager.

Return
Int: The total vertical range represented by the vertical scrollbar

computeHorizontalScrollRange

open fun computeHorizontalScrollRange(): Int

Compute the horizontal range that the horizontal scrollbar represents.

The range is expressed in arbitrary units that must be the same as the units used by #computeHorizontalScrollExtent() and #computeHorizontalScrollOffset().

Default implementation returns 0.

If you want to support scroll bars, override RecyclerView.LayoutManager#computeHorizontalScrollRange(RecyclerView.State) in your LayoutManager.

Return
Int: The total horizontal range represented by the vertical scrollbar

findViewHolderForItemId

open fun findViewHolderForItemId(id: Long): RecyclerView.ViewHolder!

Return the ViewHolder for the item with the given id. The RecyclerView must use an Adapter with stableIds to return a non-null value.

This method checks only the children of RecyclerView. If the item with the given id is not laid out, it will not create a new one. When the ItemAnimator is running a change animation, there might be 2 ViewHolders with the same id. In this case, the updated ViewHolder will be returned.

Parameters
id Long: The id for the requested item
Return
RecyclerView.ViewHolder!: The ViewHolder with the given id or null if there is no such item

hasPendingAdapterUpdates

open fun hasPendingAdapterUpdates(): Boolean

Returns whether there are pending adapter updates which are not yet applied to the layout.

If this method returns true, it means that what user is currently seeing may not reflect them adapter contents (depending on what has changed). You may use this information to defer or cancel some operations.

This method returns true if RecyclerView has not yet calculated the first layout after it is attached to the Window or the Adapter has been replaced.

Return
Boolean: True if there are some adapter updates which are not yet reflected to layout or false if layout is up to date.

setHasFixedSize

open fun setHasFixedSize(hasFixedSize: Boolean): Unit

RecyclerView can perform several optimizations if it can know in advance that RecyclerView's size is not affected by the adapter contents. RecyclerView can still change its size based on other factors (e.g. its parent's size) but this size calculation cannot depend on the size of its children or contents of its adapter (except the number of items in the adapter).

If your use of RecyclerView falls into this category, set this to true. It will allow RecyclerView to avoid invalidating the whole layout when its adapter contents change.

Parameters
hasFixedSize Boolean: true if adapter changes cannot affect the size of the RecyclerView.

addOnScrollListener

open fun addOnScrollListener(listener: RecyclerView.OnScrollListener): Unit

Add a listener that will be notified of any changes in scroll state or position.

Components that add a listener should take care to remove it when finished. Other components that take ownership of a view may call #clearOnScrollListeners() to remove all attached listeners.

Parameters
listener RecyclerView.OnScrollListener: listener to set

requestChildFocus

open fun requestChildFocus(child: View!, focused: View!): Unit

getCompatAccessibilityDelegate

open fun getCompatAccessibilityDelegate(): RecyclerViewAccessibilityDelegate?

Returns the accessibility delegate compatibility implementation used by the RecyclerView.

Return
RecyclerViewAccessibilityDelegate?: An instance of AccessibilityDelegateCompat used by RecyclerView

computeHorizontalScrollExtent

open fun computeHorizontalScrollExtent(): Int

Compute the horizontal extent of the horizontal scrollbar's thumb within the horizontal range. This value is used to compute the length of the thumb within the scrollbar's track.

The range is expressed in arbitrary units that must be the same as the units used by #computeHorizontalScrollRange() and #computeHorizontalScrollOffset().

Default implementation returns 0.

If you want to support scroll bars, override RecyclerView.LayoutManager#computeHorizontalScrollExtent(RecyclerView.State) in your LayoutManager.

Return
Int: The horizontal extent of the scrollbar's thumb

addItemDecoration

open fun addItemDecoration(decor: RecyclerView.ItemDecoration, index: Int): Unit

Add an ItemDecoration to this RecyclerView. Item decorations can affect both measurement and drawing of individual item views.

Item decorations are ordered. Decorations placed earlier in the list will be run/queried/drawn first for their effects on item views. Padding added to views will be nested; a padding added by an earlier decoration will mean further item decorations in the list will be asked to draw/pad within the previous decoration's given area.

Parameters
decor RecyclerView.ItemDecoration: Decoration to add
index RecyclerView.ItemDecoration: Position in the decoration chain to insert this decoration at. If this value is negative the decoration will be added at the end.

addItemDecoration

open fun addItemDecoration(decor: RecyclerView.ItemDecoration): Unit

Add an ItemDecoration to this RecyclerView. Item decorations can affect both measurement and drawing of individual item views.

Item decorations are ordered. Decorations placed earlier in the list will be run/queried/drawn first for their effects on item views. Padding added to views will be nested; a padding added by an earlier decoration will mean further item decorations in the list will be asked to draw/pad within the previous decoration's given area.

Parameters
decor RecyclerView.ItemDecoration: Decoration to add

computeVerticalScrollOffset

open fun computeVerticalScrollOffset(): Int

Compute the vertical offset of the vertical scrollbar's thumb within the vertical range. This value is used to compute the length of the thumb within the scrollbar's track.

The range is expressed in arbitrary units that must be the same as the units used by #computeVerticalScrollRange() and #computeVerticalScrollExtent().

Default implementation returns 0.

If you want to support scroll bars, override RecyclerView.LayoutManager#computeVerticalScrollOffset(RecyclerView.State) in your LayoutManager.

Return
Int: The vertical offset of the scrollbar's thumb

onChildAttachedToWindow

open fun onChildAttachedToWindow(child: View): Unit

Called when an item view is attached to this RecyclerView.

Subclasses of RecyclerView may want to perform extra bookkeeping or modifications of child views as they become attached. This will be called before a LayoutManager measures or lays out the view and is a good time to perform these changes.

Parameters
child View: Child view that is now attached to this RecyclerView and its associated window

setEdgeEffectFactory

open fun setEdgeEffectFactory(edgeEffectFactory: RecyclerView.EdgeEffectFactory): Unit

Set a EdgeEffectFactory for this RecyclerView.

When a new EdgeEffectFactory is set, any existing over-scroll effects are cleared and new effects are created as needed using EdgeEffectFactory#createEdgeEffect(RecyclerView, int)

Parameters
edgeEffectFactory RecyclerView.EdgeEffectFactory: The EdgeEffectFactory instance.

removeItemDecoration

open fun removeItemDecoration(decor: RecyclerView.ItemDecoration): Unit

Remove an ItemDecoration from this RecyclerView.

The given decoration will no longer impact the measurement and drawing of item views.

Parameters
decor RecyclerView.ItemDecoration: Decoration to remove

dispatchNestedScroll

open fun dispatchNestedScroll(dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, offsetInWindow: IntArray!): Boolean

dispatchNestedScroll

open fun dispatchNestedScroll(dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, offsetInWindow: IntArray!, type: Int): Boolean

setAdapter

open fun setAdapter(adapter: RecyclerView.Adapter<RecyclerView.ViewHolder!>?): Unit

Set a new adapter to provide child views on demand.

When adapter is changed, all existing views are recycled back to the pool. If the pool has only one adapter, it will be cleared.

Parameters
adapter RecyclerView.Adapter<RecyclerView.ViewHolder!>?: The new adapter to set, or null to set no adapter.

requestChildRectangleOnScreen

open fun requestChildRectangleOnScreen(child: View!, rect: Rect!, immediate: Boolean): Boolean

getOnFlingListener

open fun getOnFlingListener(): RecyclerView.OnFlingListener?

Get the current OnFlingListener from this RecyclerView.

Return
RecyclerView.OnFlingListener?: The OnFlingListener instance currently set (can be null).

getMaxFlingVelocity

open fun getMaxFlingVelocity(): Int

Returns the maximum fling velocity used by this RecyclerView.

Return
Int: The maximum fling velocity used by this RecyclerView.

getChildPosition

open fun getChildPosition(child: View): Int

generateLayoutParams

open fun generateLayoutParams(attrs: AttributeSet!): LayoutParams!

requestLayout

open fun requestLayout(): Unit

isComputingLayout

open fun isComputingLayout(): Boolean

Returns whether RecyclerView is currently computing a layout.

If this method returns true, it means that RecyclerView is in a lockdown state and any attempt to update adapter contents will result in an exception because adapter contents cannot be changed while RecyclerView is trying to compute the layout.

It is very unlikely that your code will be running during this state as it is called by the framework when a layout traversal happens or RecyclerView starts to scroll in response to system events (touch, accessibility etc).

This case may happen if you have some custom logic to change adapter contents in response to a View callback (e.g. focus change callback) which might be triggered during a layout calculation. In these cases, you should just postpone the change using a Handler or a similar mechanism.

Return
Boolean: true if RecyclerView is currently computing a layout, false otherwise

smoothScrollToPosition

open fun smoothScrollToPosition(position: Int): Unit

Starts a smooth scroll to an adapter position.

To support smooth scrolling, you must override LayoutManager#smoothScrollToPosition(RecyclerView, State, int) and create a SmoothScroller.

LayoutManager is responsible for creating the actual scroll action. If you want to provide a custom smooth scroll logic, override LayoutManager#smoothScrollToPosition(RecyclerView, State, int) in your LayoutManager.

Parameters
position Int: The adapter position to scroll to

findViewHolderForAdapterPosition

open fun findViewHolderForAdapterPosition(position: Int): RecyclerView.ViewHolder!

Return the ViewHolder for the item in the given position of the data set. Unlike #findViewHolderForLayoutPosition(int) this method takes into account any pending adapter changes that may not be reflected to the layout yet. On the other hand, if Adapter#notifyDataSetChanged() has been called but the new layout has not been calculated yet, this method will return null since the new positions of views are unknown until the layout is calculated.

This method checks only the children of RecyclerView. If the item at the given position is not laid out, it will not create a new one.

When the ItemAnimator is running a change animation, there might be 2 ViewHolders representing the same Item. In this case, the updated ViewHolder will be returned.

Parameters
position Int: The position of the item in the data set of the adapter
Return
RecyclerView.ViewHolder!: The ViewHolder at position or null if there is no such item

draw

open fun draw(c: Canvas!): Unit

dispatchNestedFling

open fun dispatchNestedFling(velocityX: Float, velocityY: Float, consumed: Boolean): Boolean

getChildViewHolder

open fun getChildViewHolder(child: View): RecyclerView.ViewHolder!

Retrieve the ViewHolder for the given child view.

Parameters
child View: Child of this RecyclerView to query for its ViewHolder
Return
RecyclerView.ViewHolder!: The child view's ViewHolder

offsetChildrenVertical

open fun offsetChildrenVertical(dy: Int): Unit

Offset the bounds of all child views by dy pixels. Useful for implementing simple scrolling in LayoutManagers.

Parameters
dy Int: Vertical pixel offset to apply to the bounds of all child views

requestDisallowInterceptTouchEvent

open fun requestDisallowInterceptTouchEvent(disallowIntercept: Boolean): Unit

findViewHolderForLayoutPosition

open fun findViewHolderForLayoutPosition(position: Int): RecyclerView.ViewHolder!

Return the ViewHolder for the item in the given position of the data set as of the latest layout pass.

This method checks only the children of RecyclerView. If the item at the given position is not laid out, it will not create a new one.

Note that when Adapter contents change, ViewHolder positions are not updated until the next layout calculation. If there are pending adapter updates, the return value of this method may not match your adapter contents. You can use #ViewHolder#getAdapterPosition() to get the current adapter position of a ViewHolder.

When the ItemAnimator is running a change animation, there might be 2 ViewHolders with the same layout position representing the same Item. In this case, the updated ViewHolder will be returned.

Parameters
position Int: The position of the item in the data set of the adapter
Return
RecyclerView.ViewHolder!: The ViewHolder at position or null if there is no such item

computeVerticalScrollExtent

open fun computeVerticalScrollExtent(): Int

Compute the vertical extent of the vertical scrollbar's thumb within the vertical range. This value is used to compute the length of the thumb within the scrollbar's track.

The range is expressed in arbitrary units that must be the same as the units used by #computeVerticalScrollRange() and #computeVerticalScrollOffset().

Default implementation returns 0.

If you want to support scroll bars, override RecyclerView.LayoutManager#computeVerticalScrollExtent(RecyclerView.State) in your LayoutManager.

Return
Int: The vertical extent of the scrollbar's thumb

setLayoutFrozen

open fun setLayoutFrozen(frozen: Boolean): Unit

Enable or disable layout and scroll. After setLayoutFrozen(true) is called, Layout requests will be postponed until setLayoutFrozen(false) is called; child views are not updated when RecyclerView is frozen, #smoothScrollBy(int, int), #scrollBy(int, int), #scrollToPosition(int) and #smoothScrollToPosition(int) are dropped; TouchEvents and GenericMotionEvents are dropped; LayoutManager#onFocusSearchFailed(View, int, Recycler, State) will not be called.

setLayoutFrozen(true) does not prevent app from directly calling , LayoutManager#smoothScrollToPosition( * RecyclerView, State, int).

#setAdapter(Adapter) and #swapAdapter(Adapter, boolean) will automatically stop frozen.

Note: Running ItemAnimator is not stopped automatically, it's caller's responsibility to call ItemAnimator.end().

Parameters
frozen Boolean: true to freeze layout and scroll, false to re-enable.

removeItemDecorationAt

open fun removeItemDecorationAt(index: Int): Unit

Removes the ItemDecoration associated with the supplied index position.

Parameters
index Int: The index position of the ItemDecoration to be removed.

swapAdapter

open fun swapAdapter(adapter: RecyclerView.Adapter<RecyclerView.ViewHolder!>?, removeAndRecycleExistingViews: Boolean): Unit

Swaps the current adapter with the provided one. It is similar to #setAdapter(Adapter) but assumes existing adapter and the new adapter uses the same ViewHolder and does not clear the RecycledViewPool.

Note that it still calls onAdapterChanged callbacks.

Parameters
adapter RecyclerView.Adapter<RecyclerView.ViewHolder!>?: The new adapter to set, or null to set no adapter.
removeAndRecycleExistingViews RecyclerView.Adapter<RecyclerView.ViewHolder!>?: If set to true, RecyclerView will recycle all existing Views. If adapters have stable ids and/or you want to animate the disappearing views, you may prefer to set this to false.

setViewCacheExtension

open fun setViewCacheExtension(extension: RecyclerView.ViewCacheExtension?): Unit

Sets a new ViewCacheExtension to be used by the Recycler.

Parameters
extension RecyclerView.ViewCacheExtension?: ViewCacheExtension to be used or null if you want to clear the existing one.

onDraw

open fun onDraw(c: Canvas!): Unit

setItemViewCacheSize

open fun setItemViewCacheSize(size: Int): Unit

Set the number of offscreen views to retain before adding them to the potentially shared recycled view pool.

The offscreen view cache stays aware of changes in the attached adapter, allowing a LayoutManager to reuse those views unmodified without needing to return to the adapter to rebind them.

Parameters
size Int: Number of views to cache offscreen before returning them to the general recycled view pool

setOnScrollListener

open fun setOnScrollListener(listener: RecyclerView.OnScrollListener?): Unit

Set a listener that will be notified of any changes in scroll state or position.

Parameters
listener RecyclerView.OnScrollListener?: Listener to set or null to clear

Protected methods

getChildDrawingOrder

protected open fun getChildDrawingOrder(childCount: Int, i: Int): Int

dispatchRestoreInstanceState

protected open fun dispatchRestoreInstanceState(container: SparseArray<Parcelable!>!): Unit

Override to prevent thawing of any views created by the adapter.

dispatchSaveInstanceState

protected open fun dispatchSaveInstanceState(container: SparseArray<Parcelable!>!): Unit

Override to prevent freezing of any views created by the adapter.

onDetachedFromWindow

protected open fun onDetachedFromWindow(): Unit

onRequestFocusInDescendants

protected open fun onRequestFocusInDescendants(direction: Int, previouslyFocusedRect: Rect!): Boolean

onMeasure

protected open fun onMeasure(widthSpec: Int, heightSpec: Int): Unit

generateDefaultLayoutParams

protected open fun generateDefaultLayoutParams(): LayoutParams!

onRestoreInstanceState

protected open fun onRestoreInstanceState(state: Parcelable!): Unit

onAttachedToWindow

protected open fun onAttachedToWindow(): Unit

checkLayoutParams

protected open fun checkLayoutParams(p: LayoutParams!): Boolean

onSizeChanged

protected open fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int): Unit

onSaveInstanceState

protected open fun onSaveInstanceState(): Parcelable!

onLayout

protected open fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int): Unit

generateLayoutParams

protected open fun generateLayoutParams(p: LayoutParams!): LayoutParams!

removeDetachedView

protected open fun removeDetachedView(child: View!, animate: Boolean): Unit