RecyclerView


class RecyclerView : ViewGroup, ScrollingView, NestedScrollingChild2, NestedScrollingChild3

Known direct subclasses
BaseGridView

An abstract base class for vertically and horizontally scrolling lists.

WearableRecyclerView

Wearable specific implementation of the RecyclerView enabling setCircularScrollingGestureEnabled circular scrolling} and semi-circular layouts.

Known indirect subclasses
HorizontalGridView

A android.view.ViewGroup that shows items in a horizontal scrolling list.

VerticalGridView

A android.view.ViewGroup that shows items in a vertically scrolling list.


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 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. getLayoutPosition, findViewHolderForLayoutPosition). 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. getAbsoluteAdapterPosition, getBindingAdapterPosition, findViewHolderForAdapterPosition) 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 getBindingAdapterPosition. Beware that these methods may not be able to calculate adapter positions if 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.

Presenting Dynamic Data

To display updatable data in a RecyclerView, your adapter needs to signal inserts, moves, and deletions to RecyclerView. You can build this yourself by manually calling adapter.notify* methods when content changes, or you can use one of the easier solutions RecyclerView provides: List diffing with DiffUtil If your RecyclerView is displaying a list that is re-fetched from scratch for each update (e.g. from the network, or from a database), DiffUtil can calculate the difference between versions of the list. DiffUtil takes both lists as input and computes the difference, which can be passed to RecyclerView to trigger minimal animations and updates to keep your UI performant, and animations meaningful. This approach requires that each list is represented in memory with immutable content, and relies on receiving updates as new instances of lists. This approach is also ideal if your UI layer doesn't implement sorting, it just presents the data in the order it's given.

The best part of this approach is that it extends to any arbitrary changes - item updates, moves, addition and removal can all be computed and handled the same way. Though you do have to keep two copies of the list in memory while diffing, and must avoid mutating them, it's possible to share unmodified elements between list versions.

There are three primary ways to do this for RecyclerView. We recommend you start with ListAdapter, the higher-level API that builds in List diffing on a background thread, with minimal code. AsyncListDiffer also provides this behavior, but without defining an Adapter to subclass. If you want more control, DiffUtil is the lower-level API you can use to compute the diffs yourself. Each approach allows you to specify how diffs should be computed based on item data.

List mutation with SortedList If your RecyclerView receives updates incrementally, e.g. item X is inserted, or item Y is removed, you can use SortedList to manage your list. You define how to order items, and it will automatically trigger update signals that RecyclerView can use. SortedList works if you only need to handle insert and remove events, and has the benefit that you only ever need to have a single copy of the list in memory. It can also compute differences with replaceAll, but this method is more limited than the list diffing behavior above. Paging Library The Paging library extends the diff-based approach to additionally support paged loading. It provides the androidx.paging.PagedList class that operates as a self-loading list, provided a source of data like a database, or paginated network API. It provides convenient list diffing support out of the box, similar to ListAdapter and AsyncListDiffer. For more information about the Paging library, see the library documentation. layoutManager

Summary

Nested types

Base class for an Adapter

Defines how this Adapter wants to restore its state after a view reconstruction (e.g. configuration change).

Observer base class for watching changes to an Adapter.

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

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

@Retention(value = RetentionPolicy.SOURCE)
@IntDef(value = )
annotation RecyclerView.EdgeEffectFactory.EdgeDirection

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

@IntDef(flag = true, value = )
@Retention(value = RetentionPolicy.SOURCE)
annotation RecyclerView.ItemAnimator.AdapterChanges

The set of flags that might be passed to recordPreLayoutInformation.

This interface is used to inform listeners when all pending or running animations in an ItemAnimator are finished.

A simple data structure that holds information about an item's bounds.

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

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.

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

Some general properties that a LayoutManager may want to use.

LayoutParams subclass for children of RecyclerView.

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

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

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.

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

RecycledViewPool lets you share Views between multiple RecyclerViews.

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

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

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

Base class for smooth scrolling.

Holds information about a smooth scroll request by a SmoothScroller.

An interface which is optionally implemented by custom RecyclerView.LayoutManager to provide a hint to a SmoothScroller about the location of the target position.

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

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

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

Constants

const Int
const Int
const Long
NO_ID = -1
const Int
const Int

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

const Int

The RecyclerView is not currently scrolling.

const Int

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

const Int

Constant for use with setScrollingTouchSlop.

const Int

Constant for use with setScrollingTouchSlop.

const Int
UNDEFINED_DURATION = -2147483648

Constant that represents that a duration has not been defined.

const Int

Public constructors

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

Public functions

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

Add an ItemDecoration to this RecyclerView.

Unit

Add an ItemDecoration to this RecyclerView.

Unit

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

Unit

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

Unit

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

Unit

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

Unit

Removes all listeners that were added via addOnChildAttachStateChangeListener.

Unit

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

Int

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

Int

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

Int

Compute the horizontal range that the horizontal scrollbar represents.

Int

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

Int

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

Int

Compute the vertical range that the vertical scrollbar represents.

Boolean
Boolean
dispatchNestedFling(velocityX: Float, velocityY: Float, consumed: Boolean)
Boolean
dispatchNestedPreFling(velocityX: Float, velocityY: Float)
Boolean
dispatchNestedPreScroll(
    dx: Int,
    dy: Int,
    consumed: IntArray!,
    offsetInWindow: IntArray!
)
Boolean
dispatchNestedPreScroll(
    dx: Int,
    dy: Int,
    consumed: IntArray!,
    offsetInWindow: IntArray!,
    type: Int
)

Dispatch one step of a nested scroll in progress before this view consumes any portion of it.

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

Dispatch one step of a nested scroll in progress.

Unit
dispatchNestedScroll(
    dxConsumed: Int,
    dyConsumed: Int,
    dxUnconsumed: Int,
    dyUnconsumed: Int,
    offsetInWindow: IntArray!,
    type: Int,
    consumed: IntArray
)

Dispatch one step of a nested scroll in progress.

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

Find the topmost view under the given point.

View?

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

RecyclerView.ViewHolder?

Returns the ViewHolder that contains the given view.

RecyclerView.ViewHolder?

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

RecyclerView.ViewHolder!

Return the ViewHolder for the item with the given id.

RecyclerView.ViewHolder?

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

RecyclerView.ViewHolder?

This function is deprecated.

use findViewHolderForLayoutPosition or findViewHolderForAdapterPosition

Boolean
fling(velocityX: Int, velocityY: Int)

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

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.

ViewGroup.LayoutParams!
CharSequence!
RecyclerView.Adapter?

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

Int

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

Int

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

Long

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

Int

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

Int

This function is deprecated.

use getChildAdapterPosition or getChildLayoutPosition.

RecyclerView.ViewHolder!

Retrieve the ViewHolder for the given child view.

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.

RecyclerViewAccessibilityDelegate?

Returns the accessibility delegate compatibility implementation used by the RecyclerView.

Unit

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

RecyclerView.EdgeEffectFactory

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

RecyclerView.ItemAnimator?

Gets the current ItemAnimator for this RecyclerView.

RecyclerView.ItemDecoration

Returns an ItemDecoration previously added to this RecyclerView.

Int

Returns the number of ItemDecoration currently added to this RecyclerView.

RecyclerView.LayoutManager?

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

Int

Returns the maximum fling velocity used by this RecyclerView.

Int

Returns the minimum velocity to start a fling.

RecyclerView.OnFlingListener?

Get the current OnFlingListener from this RecyclerView.

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.

RecyclerView.RecycledViewPool

Retrieve this RecyclerView's RecycledViewPool.

Int

Return the current scrolling state of the RecyclerView.

Boolean
Boolean
Boolean

Returns true if this view has a nested scrolling parent for the given input type.

Boolean

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

Unit

Invalidates all ItemDecorations.

Boolean

Returns true if RecyclerView is currently running some animations.

Boolean

Returns true if RecyclerView is attached to window.

Boolean

Returns whether RecyclerView is currently computing a layout.

Boolean

This function is deprecated.

Use isLayoutSuppressed.

Boolean

Returns whether layout and scroll calls on this container are currently being suppressed, due to an earlier call to suppressLayout.

Boolean
Unit

Same as scrollBy, but also participates in nested scrolling.

Unit

Offset the bounds of all child views by dx pixels.

Unit

Offset the bounds of all child views by dy pixels.

Unit

Called when an item view is attached to this RecyclerView.

Unit

Called when an item view is detached from this RecyclerView.

Unit
Boolean
Boolean
Unit

Called when the scroll state of this RecyclerView changes.

Unit
onScrolled(dx: @Px Int, dy: @Px Int)

Called when the scroll position of this RecyclerView changes.

Boolean
Unit

Remove an ItemDecoration from this RecyclerView.

Unit

Removes the ItemDecoration associated with the supplied index position.

Unit

Removes the provided listener from child attached state listeners list.

Unit

Remove an OnItemTouchListener.

Unit

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

Unit

Removes the provided listener from RecyclerListener list.

Unit
requestChildFocus(child: View!, focused: View!)
Boolean
requestChildRectangleOnScreen(child: View!, rect: Rect!, immediate: Boolean)
Unit
Unit
Unit
scrollBy(x: Int, y: Int)
Unit
scrollTo(x: Int, y: Int)
Unit
scrollToPosition(position: Int)

Convenience method to scroll to a certain position.

Unit
Unit

Sets the accessibility delegate compatibility implementation used by RecyclerView.

Unit

Set a new adapter to provide child views on demand.

Unit

Sets the ChildDrawingOrderCallback to be used for drawing children.

Unit
setClipToPadding(clipToPadding: Boolean)
java-static Unit
setDebugAssertionsEnabled(debugAssertionsEnabled: Boolean)

Enable internal assertions about RecyclerView's state and throw exceptions if the assertions are violated.

Unit

Set a EdgeEffectFactory for this RecyclerView.

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.

Unit

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

Unit

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

Unit

This function is deprecated.

Use suppressLayout.

Unit

Set the LayoutManager that this RecyclerView will use.

Unit

This function is deprecated.

Use setItemAnimator ()}.

Unit
Unit

Set a OnFlingListener for this RecyclerView.

Unit

This function is deprecated.

Use addOnScrollListener and removeOnScrollListener

Unit
setPreserveFocusAfterLayout(preserveFocusAfterLayout: Boolean)

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

Unit

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

Unit

This function is deprecated.

Use addRecyclerListener and removeRecyclerListener

Unit
setScrollingTouchSlop(slopConstant: Int)

Configure the scrolling touch slop for a specific use case.

java-static Unit
setVerboseLoggingEnabled(verboseLoggingEnabled: Boolean)

Enable verbose logging within RecyclerView itself.

Unit

Sets a new ViewCacheExtension to be used by the Recycler.

Unit
smoothScrollBy(dx: @Px Int, dy: @Px Int)

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

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

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

Unit
smoothScrollBy(
    dx: @Px Int,
    dy: @Px Int,
    interpolator: Interpolator?,
    duration: Int
)

Smooth scrolls the RecyclerView by a given distance.

Unit

Starts a smooth scroll to an adapter position.

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

Begin a nestable scroll operation along the given axes, for the given input type.

Unit
Unit

Stop a nested scroll in progress for the given input type.

Unit

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

Unit

Tells this RecyclerView to suppress all layout and scroll calls until layout suppression is disabled with a later call to suppressLayout(false).

Unit
swapAdapter(
    adapter: RecyclerView.Adapter?,
    removeAndRecycleExistingViews: Boolean
)

Swaps the current adapter with the provided one.

Protected functions

Boolean
Unit

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

Unit

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

ViewGroup.LayoutParams!
ViewGroup.LayoutParams!
Int
getChildDrawingOrder(childCount: Int, i: Int)
Unit
Unit
Unit
onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int)
Unit
onMeasure(widthSpec: Int, heightSpec: Int)
Boolean
onRequestFocusInDescendants(direction: Int, previouslyFocusedRect: Rect!)
Unit
Parcelable!
Unit
onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int)
Unit
removeDetachedView(child: View!, animate: Boolean)

Inherited Constants

From android.view.View
const Int
const Int
const Int
const Int
const Int
const Int
const Property<View!, Float!>!
const Int
const String!
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE = "creditCardExpirationDate"
const String!
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY = "creditCardExpirationDay"
const String!
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH = "creditCardExpirationMonth"
const String!
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR = "creditCardExpirationYear"
const String!
const String!
AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE = "creditCardSecurityCode"
const String!
const String!
const String!
const String!
const String!
const String!
const String!
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const Int
const Int
const Int
const Int
const Int
const Int
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const Int
const Int
const Int
const Int
const Int
const Int
const Int
GONE = 8
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
KEEP_SCREEN_ON = 67108864
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
NO_ID = -1
const Int
const Int
const Int
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const Property<View!, Float!>!
const Property<View!, Float!>!
const Property<View!, Float!>!
const Property<View!, Float!>!
const Property<View!, Float!>!
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const IntArray<Int>!
const IntArray<Int>!
const Int
const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Property<View!, Float!>!
const Property<View!, Float!>!
const Property<View!, Float!>!
const String!
VIEW_LOG_TAG = "View"
const Int
const IntArray<Int>!
const Property<View!, Float!>!
const Property<View!, Float!>!
const Property<View!, Float!>!
From android.view.ViewGroup
const Int
const Int
const Int
const Int
const Int
const Int
const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

Inherited functions

From android.view.View
Unit
Unit
Unit
ViewPropertyAnimator!
Unit
Unit
Boolean
Unit
Unit

This function is deprecated.

Unit
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Unit
Unit
Unit
Boolean
Unit
Unit
java-static Int
combineMeasuredStates(curState: Int, newState: Int)
Unit
WindowInsets!
computeSystemWindowInsets(in: WindowInsets!, outLocalInsets: Rect!)
AccessibilityNodeInfo!
Unit
Unit

This function is deprecated.

Boolean
Boolean
dispatchNestedPrePerformAccessibilityAction(
    action: Int,
    arguments: Bundle!
)
Unit
OnBackInvokedDispatcher!
T!
<T : View?> findViewById(id: Int)
T!
<T : View?> findViewWithTag(tag: Any!)
Boolean

This function is deprecated.

Unit
forceHasOverlappingRendering(hasOverlappingRendering: Boolean)
Unit
Unit
generateDisplayHash(
    hashAlgorithm: String!,
    bounds: Rect!,
    executor: Executor!,
    callback: DisplayHashResultCallback!
)
java-static Int
View.AccessibilityDelegate!
Int
AccessibilityNodeProvider!
CharSequence!
Int
Int
String!
String!
Float
Animation!
Matrix!
IBinder!
IntArray<Int>!
(Mutable)Map<Int!, Int!>!
Array<String!>!
AutofillId!
Int
AutofillValue!
Drawable!
BlendMode!
ColorStateList!
PorterDuff.Mode!
Int
Float
Int
Float
Rect!
Boolean
getClipBounds(outRect: Rect!)
Boolean
ContentCaptureSession!
CharSequence!
Context!
ContextMenu.ContextMenuInfo!
Boolean
java-static Int
getDefaultSize(size: Int, measureSpec: Int)
Display!
IntArray<Int>!
Bitmap!

This function is deprecated.

Int

This function is deprecated.

Int

This function is deprecated.

Unit
getDrawingRect(outRect: Rect!)
Long
Float
Int
Boolean
Boolean
Int
ArrayList<View!>!
getFocusables(direction: Int)
Unit
Drawable!
Int
BlendMode!
ColorStateList!
PorterDuff.Mode!
Boolean
getGlobalVisibleRect(r: Rect!, globalOffset: Point!)
Handler!
Float
Float
Float
Float
Runnable!
Boolean
Int
Unit
getHitRect(outRect: Rect!)
Int
Int
Drawable!
Drawable!
Int
Int
Int
Int
Boolean
KeyEvent.DispatcherState!
Int
Int
Int
ViewGroup.LayoutParams!
Int
Float
Int
Boolean
Unit
Unit
Unit
Matrix!
Int
Int
Int
Int
Int
Int
Int
Int
Int
Int
Int
Int
Int
View.OnFocusChangeListener!
Int
ViewOutlineProvider!
Int
Int
ViewOverlay!
Int
Int
Int
Int
Int
Int
ViewParent!
ViewParent!
Float
Float
PointerIcon!
(Mutable)List<Rect!>!
Array<String!>!
Resources!
Boolean
Int
Float
Int
AttachedSurfaceControl!
View!
WindowInsets!
Float
Float
Float
Float
Float
Int
Int
Int
Int
Int
Int
Int
Int
Int
Int
CharSequence!
StateListAnimator!
Int
Int
(Mutable)List<Rect!>!
Int

This function is deprecated.

Any!
Int
Int
CharSequence!
Int
Float
Int
TouchDelegate!
ArrayList<View!>!
Float
String!
Float
Float
Float
Long
Int
Int
Drawable!
Drawable!
Int
ViewTranslationResponse!
ViewTreeObserver!
Int
Int
Int
WindowId!
WindowInsetsController!
Int

This function is deprecated.

IBinder!
Int
Unit
Float
Float
Float
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
java-static View!
inflate(context: Context!, resource: Int, root: ViewGroup!)
Unit
invalidate(dirty: Rect!)

This function is deprecated.

Unit
Unit
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean

This function is deprecated.

Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
View!
keyboardNavigationClusterSearch(currentCluster: View!, direction: Int)
Unit
measure(widthMeasureSpec: Int, heightMeasureSpec: Int)
java-static IntArray<Int>!
mergeDrawableStates(baseState: IntArray!, additionalState: IntArray!)
Unit
Unit
Unit
Unit
WindowInsets!
Unit
Boolean
Boolean
Unit
Unit
InputConnection!
Unit
onCreateViewTranslationRequest(
    supportedFormats: IntArray!,
    requestsCollector: Consumer<ViewTranslationRequest!>!
)
Unit
onCreateVirtualViewTranslationRequests(
    virtualIds: LongArray!,
    supportedFormats: IntArray!,
    requestsCollector: Consumer<ViewTranslationRequest!>!
)
Unit
Boolean
Unit
Unit
Boolean
Unit
Unit
Unit
onFocusChanged(
    gainFocus: Boolean,
    direction: Int,
    previouslyFocusedRect: Rect!
)
Unit
Boolean
Unit
Unit
Boolean
onKeyDown(keyCode: Int, event: KeyEvent!)
Boolean
onKeyLongPress(keyCode: Int, event: KeyEvent!)
Boolean
onKeyMultiple(keyCode: Int, repeatCount: Int, event: KeyEvent!)
Boolean
onKeyPreIme(keyCode: Int, event: KeyEvent!)
Boolean
onKeyShortcut(keyCode: Int, event: KeyEvent!)
Boolean
onKeyUp(keyCode: Int, event: KeyEvent!)
Unit
onOverScrolled(
    scrollX: Int,
    scrollY: Int,
    clampedX: Boolean,
    clampedY: Boolean
)
Unit
Unit
Unit
Unit
Unit
Unit
Unit
ContentInfo!
Unit
onRtlPropertiesChanged(layoutDirection: Int)
Unit
onScreenStateChanged(screenState: Int)
Unit
onScrollCaptureSearch(
    localVisibleRect: Rect!,
    windowOffset: Point!,
    targets: Consumer<ScrollCaptureTarget!>!
)
Unit
onScrollChanged(l: Int, t: Int, oldl: Int, oldt: Int)
Boolean
onSetAlpha(alpha: Int)
Unit
Boolean
Unit
Unit
Unit
Unit
onVisibilityChanged(changedView: View!, visibility: Int)
Unit
onWindowFocusChanged(hasWindowFocus: Boolean)
Unit

This function is deprecated.

Unit
Boolean
overScrollBy(
    deltaX: Int,
    deltaY: Int,
    scrollX: Int,
    scrollY: Int,
    scrollRangeX: Int,
    scrollRangeY: Int,
    maxOverScrollX: Int,
    maxOverScrollY: Int,
    isTouchEvent: Boolean
)
Boolean
performAccessibilityAction(action: Int, arguments: Bundle!)
Boolean
Boolean
Boolean
performHapticFeedback(feedbackConstant: Int)
Boolean
ContentInfo!
Unit
playSoundEffect(soundConstant: Int)
Boolean
post(action: Runnable!)
Boolean
postDelayed(action: Runnable!, delayMillis: Long)
Unit
Unit
postInvalidateDelayed(delayMilliseconds: Long)
Unit
Unit
Unit
postOnAnimationDelayed(action: Runnable!, delayMillis: Long)
Unit
Unit
Boolean
Unit
Unit
Unit
Unit
Unit

This function is deprecated.

Boolean
Unit
Boolean
Unit
T!
<T : View?> requireViewById(id: Int)
Unit
java-static Int
resolveSize(size: Int, measureSpec: Int)
java-static Int
resolveSizeAndState(size: Int, measureSpec: Int, childMeasuredState: Int)
Unit
Unit
saveAttributeDataForStyleable(
    context: Context!,
    styleable: IntArray!,
    attrs: AttributeSet!,
    t: TypedArray!,
    defStyleAttr: Int,
    defStyleRes: Int
)
Unit
Unit
scheduleDrawable(who: Drawable!, what: Runnable!, when: Long)
Unit
Unit
setAccessibilityDataSensitive(accessibilityDataSensitive: Int)
Unit
Unit
Unit
Unit
setAccessibilityPaneTitle(accessibilityPaneTitle: CharSequence!)
Unit
Unit
Unit
setActivated(activated: Boolean)
Unit
setAllowClickWhenDisabled(clickableWhenDisabled: Boolean)
Unit
Unit
Unit
setAlpha(alpha: Float)
Unit
setAnimation(animation: Animation!)
Unit
Unit
Unit
setAutofillHints(autofillHints: Array<String!>!)
Unit
Unit
setBackground(background: Drawable!)
Unit
Unit

This function is deprecated.

Unit
Unit
Unit
Unit
Unit
setBottom(bottom: Int)
Unit
Unit
setClickable(clickable: Boolean)
Unit
setClipBounds(clipBounds: Rect!)
Unit
setClipToOutline(clipToOutline: Boolean)
Unit
Unit
setContentDescription(contentDescription: CharSequence!)
Unit
setContextClickable(contextClickable: Boolean)
Unit
setDefaultFocusHighlightEnabled(defaultFocusHighlightEnabled: Boolean)
Unit

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit
Unit
setElevation(elevation: Float)
Unit
setEnabled(enabled: Boolean)
Unit
Unit
Unit
setFitsSystemWindows(fitSystemWindows: Boolean)
Unit
setFocusable(focusable: Boolean)
Unit
setFocusableInTouchMode(focusableInTouchMode: Boolean)
Unit
setFocusedByDefault(isFocusedByDefault: Boolean)
Unit
Unit
setForeground(foreground: Drawable!)
Unit
Unit
Unit
Unit
Unit
setHandwritingBoundsOffsets(
    offsetLeft: Float,
    offsetTop: Float,
    offsetRight: Float,
    offsetBottom: Float
)
Unit
Unit
setHapticFeedbackEnabled(hapticFeedbackEnabled: Boolean)
Unit
setHasTransientState(hasTransientState: Boolean)
Unit
setHorizontalFadingEdgeEnabled(horizontalFadingEdgeEnabled: Boolean)
Unit
setHorizontalScrollBarEnabled(horizontalScrollBarEnabled: Boolean)
Unit
Unit
Unit
setHovered(hovered: Boolean)
Unit
setId(id: Int)
Unit
Unit
Unit
Unit
setIsCredential(isCredential: Boolean)
Unit
setIsHandwritingDelegate(isHandwritingDelegate: Boolean)
Unit
setKeepScreenOn(keepScreenOn: Boolean)
Unit
Unit
Unit
Unit
setLayerType(layerType: Int, paint: Paint!)
Unit
setLayoutDirection(layoutDirection: Int)
Unit
Unit
setLeft(left: Int)
Unit
setLeftTopRightBottom(left: Int, top: Int, right: Int, bottom: Int)
Unit
setLongClickable(longClickable: Boolean)
Unit
setMeasuredDimension(measuredWidth: Int, measuredHeight: Int)
Unit
setMinimumHeight(minHeight: Int)
Unit
setMinimumWidth(minWidth: Int)
Unit
setNextClusterForwardId(nextClusterForwardId: Int)
Unit
setNextFocusDownId(nextFocusDownId: Int)
Unit
setNextFocusForwardId(nextFocusForwardId: Int)
Unit
setNextFocusLeftId(nextFocusLeftId: Int)
Unit
setNextFocusRightId(nextFocusRightId: Int)
Unit
setNextFocusUpId(nextFocusUpId: Int)
Unit
Unit
Unit
Unit
Unit
Unit
Unit
Unit
Unit
Unit
Unit
Unit
setOnReceiveContentListener(
    mimeTypes: Array<String!>!,
    listener: OnReceiveContentListener!
)
Unit
Unit

This function is deprecated.

Unit
Unit
Unit
Unit
Unit
setOverScrollMode(overScrollMode: Int)
Unit
setPadding(left: Int, top: Int, right: Int, bottom: Int)
Unit
setPaddingRelative(start: Int, top: Int, end: Int, bottom: Int)
Unit
setPivotX(pivotX: Float)
Unit
setPivotY(pivotY: Float)
Unit
setPointerIcon(pointerIcon: PointerIcon!)
Unit
setPreferKeepClear(preferKeepClear: Boolean)
Unit
Unit
setPressed(pressed: Boolean)
Unit
setRenderEffect(renderEffect: RenderEffect!)
Unit
setRevealOnFocusHint(revealOnFocus: Boolean)
Unit
setRight(right: Int)
Unit
setRotation(rotation: Float)
Unit
setRotationX(rotationX: Float)
Unit
setRotationY(rotationY: Float)
Unit
Unit
Unit
setScaleX(scaleX: Float)
Unit
setScaleY(scaleY: Float)
Unit
setScreenReaderFocusable(screenReaderFocusable: Boolean)
Unit
setScrollBarDefaultDelayBeforeFade(
    scrollBarDefaultDelayBeforeFade: Int
)
Unit
setScrollBarFadeDuration(scrollBarFadeDuration: Int)
Unit
setScrollBarSize(scrollBarSize: Int)
Unit
Unit
Unit
Unit
setScrollContainer(isScrollContainer: Boolean)
Unit
setScrollIndicators(indicators: Int)
Unit
setScrollX(value: Int)
Unit
setScrollY(value: Int)
Unit
Unit
setSelected(selected: Boolean)
Unit
setSoundEffectsEnabled(soundEffectsEnabled: Boolean)
Unit
setStateDescription(stateDescription: CharSequence!)
Unit
Unit
Unit

This function is deprecated.

Unit
setTag(tag: Any!)
Unit
setTextAlignment(textAlignment: Int)
Unit
setTextDirection(textDirection: Int)
Unit
Unit
setTop(top: Int)
Unit
Unit
Unit
setTransitionName(transitionName: String!)
Unit
Unit
setTranslationX(translationX: Float)
Unit
setTranslationY(translationY: Float)
Unit
setTranslationZ(translationZ: Float)
Unit
setVerticalFadingEdgeEnabled(verticalFadingEdgeEnabled: Boolean)
Unit
setVerticalScrollBarEnabled(verticalScrollBarEnabled: Boolean)
Unit
Unit
Unit
Unit
Unit
setVisibility(visibility: Int)
Unit
setWillNotCacheDrawing(willNotCacheDrawing: Boolean)

This function is deprecated.

Unit
setWillNotDraw(willNotDraw: Boolean)
Unit
setX(x: Float)
Unit
setY(y: Float)
Unit
setZ(z: Float)
Boolean
ActionMode!
Unit
Boolean
startDrag(
    data: ClipData!,
    shadowBuilder: View.DragShadowBuilder!,
    myLocalState: Any!,
    flags: Int
)

This function is deprecated.

Boolean
startDragAndDrop(
    data: ClipData!,
    shadowBuilder: View.DragShadowBuilder!,
    myLocalState: Any!,
    flags: Int
)
String!
Unit
Unit
Unit
Unit
Boolean
Boolean

This function is deprecated.

Boolean
From android.view.ViewGroup
Unit
Unit
addExtraDataToAccessibilityNodeInfo(
    info: AccessibilityNodeInfo!,
    extraDataKey: String!,
    arguments: Bundle!
)
Unit
addKeyboardNavigationClusters(
    views: (Mutable)Collection<View!>!,
    direction: Int
)
Boolean
Unit
Unit
addView(child: View!)
Boolean
addViewInLayout(child: View!, index: Int, params: ViewGroup.LayoutParams!)
Unit
attachLayoutAnimationParameters(
    child: View!,
    params: ViewGroup.LayoutParams!,
    index: Int,
    count: Int
)
Unit
attachViewToParent(child: View!, index: Int, params: ViewGroup.LayoutParams!)
Unit
Boolean
Unit
Unit
childHasTransientStateChanged(
    child: View!,
    childHasTransientState: Boolean
)
Unit
Unit
Unit
Unit
Unit
debug(depth: Int)
Unit
Unit
Unit
detachViewsFromParent(start: Int, count: Int)
WindowInsets!
Boolean
Unit
Unit
dispatchCreateViewTranslationRequest(
    viewIds: (Mutable)Map<AutofillId!, LongArray!>!,
    supportedFormats: IntArray!,
    capability: TranslationCapability!,
    requests: (Mutable)List<ViewTranslationRequest!>!
)
Unit
Boolean
Unit
dispatchDraw(canvas: Canvas!)
Unit
Unit
Unit
Boolean
Boolean
Boolean
Boolean
Boolean
Unit
Unit
Unit
Unit
dispatchScrollCaptureSearch(
    localVisibleRect: Rect!,
    windowOffset: Point!,
    targets: Consumer<ScrollCaptureTarget!>!
)
Unit
Unit
Unit
Unit
Unit

This function is deprecated.

Unit
Boolean
Boolean
Boolean
dispatchUnhandledMove(focused: View!, direction: Int)
Unit
dispatchVisibilityChanged(changedView: View!, visibility: Int)
Unit
Unit
Unit
WindowInsets!
dispatchWindowInsetsAnimationProgress(
    insets: WindowInsets!,
    runningAnimations: (Mutable)List<WindowInsetsAnimation!>!
)
WindowInsetsAnimation.Bounds!
Unit

This function is deprecated.

Unit
Unit
Unit
View!
OnBackInvokedDispatcher!
Unit
findViewsWithText(
    outViews: ArrayList<View!>!,
    text: CharSequence!,
    flags: Int
)
Unit
Boolean
View!
getChildAt(index: Int)
Int
java-static Int
getChildMeasureSpec(spec: Int, padding: Int, childDimension: Int)
Boolean
Boolean
getChildVisibleRect(child: View!, r: Rect!, offset: Point!)
Boolean
Int
View!
LayoutAnimationController!
Animation.AnimationListener!
Int
LayoutTransition!
Int
ViewGroupOverlay!
Int

This function is deprecated.

Boolean
Boolean
Boolean
Int
indexOfChild(child: View!)
Unit
invalidateChild(child: View!, dirty: Rect!)

This function is deprecated.

ViewParent!
invalidateChildInParent(location: IntArray!, dirty: Rect!)

This function is deprecated.

Boolean

This function is deprecated.

Boolean

This function is deprecated.

Boolean
Boolean

This function is deprecated.

Boolean
Boolean
Unit
Unit
layout(l: Int, t: Int, r: Int, b: Int)
Unit
measureChild(
    child: View!,
    parentWidthMeasureSpec: Int,
    parentHeightMeasureSpec: Int
)
Unit
measureChildWithMargins(
    child: View!,
    parentWidthMeasureSpec: Int,
    widthUsed: Int,
    parentHeightMeasureSpec: Int,
    heightUsed: Int
)
Unit
measureChildren(widthMeasureSpec: Int, heightMeasureSpec: Int)
Unit
notifySubtreeAccessibilityStateChanged(
    child: View!,
    source: View!,
    changeType: Int
)
Unit
offsetDescendantRectToMyCoords(descendant: View!, rect: Rect!)
Unit
offsetRectIntoDescendantCoords(descendant: View!, rect: Rect!)
IntArray<Int>!
Unit
onDescendantInvalidated(child: View!, target: View!)
Boolean
Boolean
onNestedFling(
    target: View!,
    velocityX: Float,
    velocityY: Float,
    consumed: Boolean
)
Boolean
onNestedPreFling(target: View!, velocityX: Float, velocityY: Float)
Boolean
onNestedPrePerformAccessibilityAction(
    target: View!,
    action: Int,
    args: Bundle!
)
Unit
onNestedPreScroll(target: View!, dx: Int, dy: Int, consumed: IntArray!)
Unit
onNestedScroll(
    target: View!,
    dxConsumed: Int,
    dyConsumed: Int,
    dxUnconsumed: Int,
    dyUnconsumed: Int
)
Unit
onNestedScrollAccepted(child: View!, target: View!, axes: Int)
Boolean
PointerIcon!
onResolvePointerIcon(event: MotionEvent!, pointerIndex: Int)
Boolean
onStartNestedScroll(child: View!, target: View!, nestedScrollAxes: Int)
Unit
Unit
onViewAdded(child: View!)
Unit
Unit
Unit
Unit
Unit
removeView(view: View!)
Unit
removeViewAt(index: Int)
Unit
Unit
removeViews(start: Int, count: Int)
Unit
removeViewsInLayout(start: Int, count: Int)
Boolean
requestFocus(direction: Int, previouslyFocusedRect: Rect!)
Boolean
Unit
Boolean
Unit
Unit
Unit

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit
Unit

This function is deprecated.

Unit
setClipChildren(clipChildren: Boolean)
Unit
Unit
Unit
Unit
setLayoutMode(layoutMode: Int)
Unit
Unit
Unit
setPersistentDrawingCache(drawingCacheToKeep: Int)

This function is deprecated.

Unit
Unit
setTouchscreenBlocksFocus(touchscreenBlocksFocus: Boolean)
Unit
setTransitionGroup(isTransitionGroup: Boolean)
Unit
Boolean
Boolean
showContextMenuForChild(originalView: View!)
ActionMode!
startActionModeForChild(
    originalView: View!,
    callback: ActionMode.Callback!
)
Unit
Unit
Unit

Constants

HORIZONTAL

Added in 1.0.0
const val HORIZONTAL = 0: Int

INVALID_TYPE

Added in 1.0.0
const val INVALID_TYPE = -1: Int

NO_ID

Added in 1.0.0
const val NO_ID = -1: Long

NO_POSITION

Added in 1.0.0
const val NO_POSITION = -1: Int

SCROLL_STATE_DRAGGING

Added in 1.0.0
const val SCROLL_STATE_DRAGGING = 1: Int

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

See also
getScrollState

SCROLL_STATE_IDLE

Added in 1.0.0
const val SCROLL_STATE_IDLE = 0: Int

The RecyclerView is not currently scrolling.

See also
getScrollState

SCROLL_STATE_SETTLING

Added in 1.0.0
const val SCROLL_STATE_SETTLING = 2: Int

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

See also
getScrollState

TOUCH_SLOP_DEFAULT

Added in 1.0.0
const val TOUCH_SLOP_DEFAULT = 0: Int

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

TOUCH_SLOP_PAGING

Added in 1.0.0
const val TOUCH_SLOP_PAGING = 1: Int

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

UNDEFINED_DURATION

Added in 1.1.0
const val UNDEFINED_DURATION = -2147483648: Int

Constant that represents that a duration has not been defined.

VERTICAL

Added in 1.0.0
const val VERTICAL = 1: Int

Public constructors

RecyclerView

Added in 1.0.0
RecyclerView(context: Context)

RecyclerView

Added in 1.0.0
RecyclerView(context: Context, attrs: AttributeSet?)

RecyclerView

Added in 1.0.0
RecyclerView(context: Context, attrs: AttributeSet?, defStyleAttr: Int)

Public functions

addFocusables

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

addItemDecoration

Added in 1.0.0
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

addItemDecoration

Added in 1.0.0
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: Int

Position in the decoration chain to insert this decoration at. If this value is negative the decoration will be added at the end.

addOnChildAttachStateChangeListener

Added in 1.0.0
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

addOnItemTouchListener

Added in 1.0.0
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 onInterceptTouchEvent its onTouchEvent method will be called for each incoming MotionEvent until the end of the gesture.

Parameters
listener: RecyclerView.OnItemTouchListener

Listener to add

addOnScrollListener

Added in 1.0.0
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

addRecyclerListener

Added in 1.2.0
fun addRecyclerListener(listener: RecyclerView.RecyclerListener): Unit

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

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

Parameters
listener: RecyclerView.RecyclerListener

Listener to register.

clearOnChildAttachStateChangeListeners

Added in 1.0.0
fun clearOnChildAttachStateChangeListeners(): Unit

Removes all listeners that were added via addOnChildAttachStateChangeListener.

clearOnScrollListeners

Added in 1.0.0
fun clearOnScrollListeners(): Unit

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

computeHorizontalScrollExtent

Added in 1.0.0
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 computeHorizontalScrollExtent in your LayoutManager.

Returns
Int

The horizontal extent of the scrollbar's thumb

computeHorizontalScrollOffset

Added in 1.0.0
fun computeHorizontalScrollOffset(): Int

Compute the horizontal offset of the horizontal scrollbar's thumb within the horizontal range. This value is used to compute the position 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 computeHorizontalScrollOffset in your LayoutManager.

Returns
Int

The horizontal offset of the scrollbar's thumb

See also
computeHorizontalScrollOffset

(RecyclerView.State)

computeHorizontalScrollRange

Added in 1.0.0
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 computeHorizontalScrollRange in your LayoutManager.

Returns
Int

The total horizontal range represented by the horizontal scrollbar

computeVerticalScrollExtent

Added in 1.0.0
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 computeVerticalScrollExtent in your LayoutManager.

Returns
Int

The vertical extent of the scrollbar's thumb

computeVerticalScrollOffset

Added in 1.0.0
fun computeVerticalScrollOffset(): Int

Compute the vertical offset of the vertical scrollbar's thumb within the vertical range. This value is used to compute the position 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 computeVerticalScrollOffset in your LayoutManager.

Returns
Int

The vertical offset of the scrollbar's thumb

See also
computeVerticalScrollOffset

(RecyclerView.State)

computeVerticalScrollRange

Added in 1.0.0
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 computeVerticalScrollRange in your LayoutManager.

Returns
Int

The total vertical range represented by the vertical scrollbar

dispatchKeyEvent

fun dispatchKeyEvent(event: KeyEvent?): Boolean

dispatchNestedFling

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

dispatchNestedPreFling

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

dispatchNestedPreScroll

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

dispatchNestedPreScroll

Added in 1.0.0
fun dispatchNestedPreScroll(
    dx: Int,
    dy: Int,
    consumed: IntArray!,
    offsetInWindow: IntArray!,
    type: Int
): Boolean

Dispatch one step of a nested scroll in progress before this view consumes any portion of it.

Nested pre-scroll events are to nested scroll events what touch intercept is to touch. dispatchNestedPreScroll offers an opportunity for the parent view in a nested scrolling operation to consume some or all of the scroll operation before the child view consumes it.

Parameters
dx: Int

Horizontal scroll distance in pixels

dy: Int

Vertical scroll distance in pixels

consumed: IntArray!

Output. If not null, consumed[0] will contain the consumed component of dx and consumed[1] the consumed dy.

offsetInWindow: IntArray!

Optional. If not null, on return this will contain the offset in local view coordinates of this view from before this operation to after it completes. View implementations may use this to adjust expected input coordinate tracking.

type: Int

the type of input which cause this scroll event

Returns
Boolean

true if the parent consumed some or all of the scroll delta

dispatchNestedScroll

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

dispatchNestedScroll

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

Dispatch one step of a nested scroll in progress.

Implementations of views that support nested scrolling should call this to report info about a scroll in progress to the current nested scrolling parent. If a nested scroll is not currently in progress or nested scrolling is not enabled for this view this method does nothing.

Compatible View implementations should also call dispatchNestedPreScroll before consuming a component of the scroll event themselves.

Parameters
dxConsumed: Int

Horizontal distance in pixels consumed by this view during this scroll step

dyConsumed: Int

Vertical distance in pixels consumed by this view during this scroll step

dxUnconsumed: Int

Horizontal scroll distance in pixels not consumed by this view

dyUnconsumed: Int

Horizontal scroll distance in pixels not consumed by this view

offsetInWindow: IntArray!

Optional. If not null, on return this will contain the offset in local view coordinates of this view from before this operation to after it completes. View implementations may use this to adjust expected input coordinate tracking.

type: Int

the type of input which cause this scroll event

Returns
Boolean

true if the event was dispatched, false if it could not be dispatched.

dispatchNestedScroll

Added in 1.1.0
fun dispatchNestedScroll(
    dxConsumed: Int,
    dyConsumed: Int,
    dxUnconsumed: Int,
    dyUnconsumed: Int,
    offsetInWindow: IntArray!,
    type: Int,
    consumed: IntArray
): Unit

Dispatch one step of a nested scroll in progress.

Implementations of views that support nested scrolling should call this to report info about a scroll in progress to the current nested scrolling parent. If a nested scroll is not currently in progress or nested scrolling is not enabled for this view this method does nothing.

Compatible View implementations should also call dispatchNestedPreScroll before consuming a component of the scroll event themselves.

The original nested scrolling child (where the input events were received to start the scroll) must provide a non-null consumed parameter with values {0, 0}.

Parameters
dxConsumed: Int

Horizontal distance in pixels consumed by this view during this scroll step

dyConsumed: Int

Vertical distance in pixels consumed by this view during this scroll step

dxUnconsumed: Int

Horizontal scroll distance in pixels not consumed by this view

dyUnconsumed: Int

Horizontal scroll distance in pixels not consumed by this view

offsetInWindow: IntArray!

Optional. If not null, on return this will contain the offset in local view coordinates of this view from before this operation to after it completes. View implementations may use this to adjust expected input coordinate tracking.

type: Int

the type of input which cause this scroll event

consumed: IntArray

Output. Upon this method returning, will contain the original values plus any scroll distances consumed by all of this view's nested scrolling parents up the view hierarchy. Index 0 for the x dimension, and index 1 for the y dimension

See also
onNestedScroll

dispatchPopulateAccessibilityEvent

fun dispatchPopulateAccessibilityEvent(event: AccessibilityEvent!): Boolean

draw

fun draw(c: Canvas): Unit

drawChild

Added in 1.0.0
fun drawChild(canvas: Canvas, child: View!, drawingTime: Long): Boolean

findChildViewUnder

Added in 1.0.0
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

Returns
View?

The child view under (x, y) or null if no matching child is found

findContainingItemView

Added in 1.0.0
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.

Parameters
view: View

The view that is a descendant of the RecyclerView.

Returns
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.

findContainingViewHolder

Added in 1.0.0
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.

Returns
RecyclerView.ViewHolder?

The ViewHolder that contains the given view or null if the provided view is not a descendant of this RecyclerView.

findViewHolderForAdapterPosition

Added in 1.0.0
fun findViewHolderForAdapterPosition(position: Int): RecyclerView.ViewHolder?

Return the ViewHolder for the item in the given position of the data set. Unlike findViewHolderForLayoutPosition this method takes into account any pending adapter changes that may not be reflected to the layout yet. On the other hand, if 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

Returns
RecyclerView.ViewHolder?

The ViewHolder at position or null if there is no such item

findViewHolderForItemId

Added in 1.0.0
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

Returns
RecyclerView.ViewHolder!

The ViewHolder with the given id or null if there is no such item

findViewHolderForLayoutPosition

Added in 1.0.0
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 #getBindingAdapterPosition to get the current adapter position of a ViewHolder. If the Adapter that is assigned to the RecyclerView is an adapter that combines other adapters (e.g. ConcatAdapter), you can use the getBindingAdapter) to find the position relative to the Adapter that bound the 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

Returns
RecyclerView.ViewHolder?

The ViewHolder at position or null if there is no such item

findViewHolderForPosition

Added in 1.0.0
Deprecated in 1.0.0
fun findViewHolderForPosition(position: Int): RecyclerView.ViewHolder?

fling

Added in 1.0.0
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

Returns
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.

focusSearch

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 onFocusSearchFailed 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 FOCUS_FORWARD or 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 onFocusSearchFailed 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: Int

One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_FORWARD, FOCUS_BACKWARD or 0 for not applicable.

Returns
View!

A new View that can be the next focus after the focused View

generateLayoutParams

fun generateLayoutParams(attrs: AttributeSet!): ViewGroup.LayoutParams!

getAccessibilityClassName

fun getAccessibilityClassName(): CharSequence!

getAdapter

Added in 1.0.0
fun getAdapter(): RecyclerView.Adapter?

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

Returns
RecyclerView.Adapter?

The previously set adapter

See also
setAdapter

getBaseline

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.

Returns
Int

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

getChildAdapterPosition

Added in 1.0.0
fun getChildAdapterPosition(child: View): Int

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

Parameters
child: View

Child View to query

Returns
Int

Adapter position corresponding to the given view or NO_POSITION

getChildItemId

Added in 1.0.0
fun getChildItemId(child: View): Long

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

Parameters
child: View

Child View to query

Returns
Long

Item id corresponding to the given view or NO_ID

getChildLayoutPosition

Added in 1.0.0
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

Returns
Int

Adapter position of the given View as of last layout pass or NO_POSITION if the View is representing a removed item.

getChildPosition

Added in 1.0.0
Deprecated in 1.0.0
fun getChildPosition(child: View): Int

getChildViewHolder

Added in 1.0.0
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

Returns
RecyclerView.ViewHolder!

The child view's ViewHolder

getClipToPadding

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.

name android:clipToPadding

Returns
Boolean

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

getCompatAccessibilityDelegate

Added in 1.0.0
fun getCompatAccessibilityDelegate(): RecyclerViewAccessibilityDelegate?

Returns the accessibility delegate compatibility implementation used by the RecyclerView.

Returns
RecyclerViewAccessibilityDelegate?

An instance of AccessibilityDelegateCompat used by RecyclerView

getDecoratedBoundsWithMargins

Added in 1.0.0
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: Rect

A rect that will receive the bounds of the element including its decoration and margins.

getEdgeEffectFactory

Added in 1.0.0
fun getEdgeEffectFactory(): RecyclerView.EdgeEffectFactory

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

getItemAnimator

Added in 1.0.0
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.

Returns
RecyclerView.ItemAnimator?

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

getItemDecorationAt

Added in 1.0.0
fun getItemDecorationAt(index: Int): RecyclerView.ItemDecoration

Returns an ItemDecoration previously added to this RecyclerView.

Parameters
index: Int

The index position of the desired ItemDecoration.

Returns
RecyclerView.ItemDecoration

the ItemDecoration at index position

Throws
java.lang.IndexOutOfBoundsException

on invalid index

getItemDecorationCount

Added in 1.0.0
fun getItemDecorationCount(): Int

Returns the number of ItemDecoration currently added to this RecyclerView.

Returns
Int

number of ItemDecorations currently added added to this RecyclerView.

getLayoutManager

Added in 1.0.0
fun getLayoutManager(): RecyclerView.LayoutManager?

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

Returns
RecyclerView.LayoutManager?

The currently bound LayoutManager

getMaxFlingVelocity

Added in 1.0.0
fun getMaxFlingVelocity(): Int

Returns the maximum fling velocity used by this RecyclerView.

Returns
Int

The maximum fling velocity used by this RecyclerView.

getMinFlingVelocity

Added in 1.0.0
fun getMinFlingVelocity(): Int

Returns the minimum velocity to start a fling.

Returns
Int

The minimum velocity to start a fling

getOnFlingListener

Added in 1.0.0
fun getOnFlingListener(): RecyclerView.OnFlingListener?

Get the current OnFlingListener from this RecyclerView.

Returns
RecyclerView.OnFlingListener?

The OnFlingListener instance currently set (can be null).

getPreserveFocusAfterLayout

Added in 1.0.0
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.

Returns
Boolean

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

getRecycledViewPool

Added in 1.0.0
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.

Returns
RecyclerView.RecycledViewPool

The pool used to store recycled item views for reuse.

getScrollState

Added in 1.0.0
fun getScrollState(): Int

Return the current scrolling state of the RecyclerView.

hasFixedSize

Added in 1.0.0
fun hasFixedSize(): Boolean
Returns
Boolean

true if the app has specified that changes in adapter content cannot change the size of the RecyclerView itself.

hasNestedScrollingParent

fun hasNestedScrollingParent(): Boolean

hasNestedScrollingParent

Added in 1.0.0
fun hasNestedScrollingParent(type: Int): Boolean

Returns true if this view has a nested scrolling parent for the given input type.

The presence of a nested scrolling parent indicates that this view has initiated a nested scroll and it was accepted by an ancestor view further up the view hierarchy.

Parameters
type: Int

the type of input which cause this scroll event

Returns
Boolean

whether this view has a nested scrolling parent

hasPendingAdapterUpdates

Added in 1.0.0
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.

Returns
Boolean

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

invalidateItemDecorations

Added in 1.0.0
fun invalidateItemDecorations(): Unit

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

isAnimating

Added in 1.0.0
fun isAnimating(): Boolean

Returns true if RecyclerView is currently running some animations.

If you want to be notified when animations are finished, use isRunning.

Returns
Boolean

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

isAttachedToWindow

fun isAttachedToWindow(): Boolean

Returns true if RecyclerView is attached to window.

isComputingLayout

Added in 1.0.0
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.

Returns
Boolean

true if RecyclerView is currently computing a layout, false otherwise

isLayoutFrozen

Added in 1.0.0
Deprecated in 1.1.0
fun isLayoutFrozen(): Boolean
Returns
Boolean

true if layout and scroll are frozen

isLayoutSuppressed

Added in 1.1.0
fun isLayoutSuppressed(): Boolean

Returns whether layout and scroll calls on this container are currently being suppressed, due to an earlier call to suppressLayout.

Returns
Boolean

true if layout and scroll are currently suppressed, false otherwise.

isNestedScrollingEnabled

fun isNestedScrollingEnabled(): Boolean

nestedScrollBy

Added in 1.2.0
fun nestedScrollBy(x: Int, y: Int): Unit

Same as scrollBy, but also participates in nested scrolling.

Parameters
x: Int

The amount of horizontal scroll requested

y: Int

The amount of vertical scroll requested

offsetChildrenHorizontal

Added in 1.0.0
fun offsetChildrenHorizontal(dx: @Px Int): Unit

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

Parameters
dx: @Px Int

Horizontal pixel offset to apply to the bounds of all child views

offsetChildrenVertical

Added in 1.0.0
fun offsetChildrenVertical(dy: @Px Int): Unit

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

Parameters
dy: @Px Int

Vertical pixel offset to apply to the bounds of all child views

onChildAttachedToWindow

Added in 1.0.0
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

onChildDetachedFromWindow

Added in 1.0.0
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

onDraw

Added in 1.0.0
fun onDraw(c: Canvas): Unit

onGenericMotionEvent

fun onGenericMotionEvent(event: MotionEvent!): Boolean

onInterceptTouchEvent

fun onInterceptTouchEvent(e: MotionEvent!): Boolean

onScrollStateChanged

Added in 1.0.0
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

onScrolled

Added in 1.0.0
fun onScrolled(dx: @Px Int, dy: @Px 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 onScrollChanged 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 getScrollX and 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: @Px Int

horizontal distance scrolled in pixels

dy: @Px Int

vertical distance scrolled in pixels

onTouchEvent

fun onTouchEvent(e: MotionEvent!): Boolean

removeItemDecoration

Added in 1.0.0
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

removeItemDecorationAt

Added in 1.0.0
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.

removeOnChildAttachStateChangeListener

Added in 1.0.0
fun removeOnChildAttachStateChangeListener(
    listener: RecyclerView.OnChildAttachStateChangeListener
): Unit

Removes the provided listener from child attached state listeners list.

Parameters
listener: RecyclerView.OnChildAttachStateChangeListener

Listener to unregister

removeOnItemTouchListener

Added in 1.0.0
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

removeOnScrollListener

Added in 1.0.0
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

removeRecyclerListener

Added in 1.2.0
fun removeRecyclerListener(listener: RecyclerView.RecyclerListener): Unit

Removes the provided listener from RecyclerListener list.

Parameters
listener: RecyclerView.RecyclerListener

Listener to unregister.

requestChildFocus

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

requestChildRectangleOnScreen

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

requestDisallowInterceptTouchEvent

fun requestDisallowInterceptTouchEvent(disallowIntercept: Boolean): Unit

requestLayout

fun requestLayout(): Unit

scrollBy

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

scrollTo

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

scrollToPosition

Added in 1.0.0
fun scrollToPosition(position: Int): Unit

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

Parameters
position: Int

Scroll to this adapter position

See also
scrollToPosition

sendAccessibilityEventUnchecked

fun sendAccessibilityEventUnchecked(event: AccessibilityEvent!): Unit

setAccessibilityDelegateCompat

Added in 1.0.0
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.

setAdapter

Added in 1.0.0
fun setAdapter(adapter: RecyclerView.Adapter?): 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?

The new adapter to set, or null to set no adapter.

See also
swapAdapter

setChildDrawingOrderCallback

Added in 1.0.0
fun setChildDrawingOrderCallback(
    childDrawingOrderCallback: RecyclerView.ChildDrawingOrderCallback?
): Unit

Sets the ChildDrawingOrderCallback to be used for drawing children.

See getChildDrawingOrder for details. Calling this method will always call setChildrenDrawingOrderEnabled. 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.

setClipToPadding

fun setClipToPadding(clipToPadding: Boolean): Unit

setDebugAssertionsEnabled

Added in 1.4.0-rc01
java-static fun setDebugAssertionsEnabled(debugAssertionsEnabled: Boolean): Unit

Enable internal assertions about RecyclerView's state and throw exceptions if the assertions are violated.

This is primarily intended to diagnose problems with RecyclerView, and should not be enabled in production unless you have a specific reason to do so.

Enabling this may negatively affect performance and/or stability.

Parameters
debugAssertionsEnabled: Boolean

true to enable assertions; false to disable them

setEdgeEffectFactory

Added in 1.0.0
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 createEdgeEffect

Parameters
edgeEffectFactory: RecyclerView.EdgeEffectFactory

The EdgeEffectFactory instance.

setHasFixedSize

Added in 1.0.0
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.

setItemAnimator

Added in 1.0.0
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.

setItemViewCacheSize

Added in 1.0.0
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

setLayoutFrozen

Added in 1.0.0
Deprecated in 1.1.0
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, scrollBy, scrollToPosition and smoothScrollToPosition are dropped; TouchEvents and GenericMotionEvents are dropped; onFocusSearchFailed will not be called.

setLayoutFrozen(true) does not prevent app from directly calling scrollToPosition, smoothScrollToPosition.

setAdapter and swapAdapter 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.

setLayoutManager

Added in 1.0.0
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

setLayoutTransition

Added in 1.1.0
Deprecated in 1.1.0
fun setLayoutTransition(transition: LayoutTransition!): Unit

setNestedScrollingEnabled

fun setNestedScrollingEnabled(enabled: Boolean): Unit

setOnFlingListener

Added in 1.0.0
fun setOnFlingListener(onFlingListener: RecyclerView.OnFlingListener?): Unit

Set a OnFlingListener for this RecyclerView.

If the OnFlingListener is set then it will receive calls to fling and will be able to intercept them.

Parameters
onFlingListener: RecyclerView.OnFlingListener?

The OnFlingListener instance.

setOnScrollListener

Added in 1.0.0
Deprecated in 1.0.0
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

setPreserveFocusAfterLayout

Added in 1.0.0
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.

setRecycledViewPool

Added in 1.0.0
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 androidx.viewpager.widget.ViewPager.

Parameters
pool: RecyclerView.RecycledViewPool?

Pool to set. If this parameter is null a new pool will be created and used.

setRecyclerListener

Added in 1.0.0
Deprecated in 1.2.0
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

setScrollingTouchSlop

Added in 1.0.0
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

setVerboseLoggingEnabled

Added in 1.4.0-rc01
java-static fun setVerboseLoggingEnabled(verboseLoggingEnabled: Boolean): Unit

Enable verbose logging within RecyclerView itself.

Enabling this may negatively affect performance and reduce the utility of logcat due to high-volume logging. This generally should not be enabled in production unless you have a specific reason for doing so.

Parameters
verboseLoggingEnabled: Boolean

true to enable logging; false to disable it

setViewCacheExtension

Added in 1.0.0
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.

smoothScrollBy

Added in 1.0.0
fun smoothScrollBy(dx: @Px Int, dy: @Px Int): Unit

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

Parameters
dx: @Px Int

Pixels to scroll horizontally

dy: @Px Int

Pixels to scroll vertically

smoothScrollBy

Added in 1.0.0
fun smoothScrollBy(dx: @Px Int, dy: @Px Int, interpolator: Interpolator?): Unit

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

Parameters
dx: @Px Int

Pixels to scroll horizontally

dy: @Px Int

Pixels to scroll vertically

interpolator: Interpolator?

Interpolator to be used for scrolling. If it is null, RecyclerView will use an internal default interpolator.

smoothScrollBy

Added in 1.1.0
fun smoothScrollBy(
    dx: @Px Int,
    dy: @Px Int,
    interpolator: Interpolator?,
    duration: Int
): Unit

Smooth scrolls the RecyclerView by a given distance.

Parameters
dx: @Px Int

x distance in pixels.

dy: @Px Int

y distance in pixels.

interpolator: Interpolator?

Interpolator to be used for scrolling. If it is null, RecyclerView will use an internal default interpolator.

duration: Int

Duration of the animation in milliseconds. Set to UNDEFINED_DURATION to have the duration be automatically calculated based on an internally defined standard initial velocity. A duration less than 1 (that does not equal UNDEFINED_DURATION), will result in a call to scrollBy.

smoothScrollToPosition

Added in 1.0.0
fun smoothScrollToPosition(position: Int): Unit

Starts a smooth scroll to an adapter position.

To support smooth scrolling, you must override smoothScrollToPosition and create a SmoothScroller.

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

Parameters
position: Int

The adapter position to scroll to

startNestedScroll

fun startNestedScroll(axes: Int): Boolean

startNestedScroll

Added in 1.0.0
fun startNestedScroll(axes: Int, type: Int): Boolean

Begin a nestable scroll operation along the given axes, for the given input type.

A view starting a nested scroll promises to abide by the following contract:

The view will call startNestedScroll upon initiating a scroll operation. In the case of a touch scroll type this corresponds to the initial ACTION_DOWN. In the case of touch scrolling the nested scroll will be terminated automatically in the same manner as requestDisallowInterceptTouchEvent. In the event of programmatic scrolling the caller must explicitly call stopNestedScroll to indicate the end of the nested scroll.

If startNestedScroll returns true, a cooperative parent was found. If it returns false the caller may ignore the rest of this contract until the next scroll. Calling startNestedScroll while a nested scroll is already in progress will return true.

At each incremental step of the scroll the caller should invoke dispatchNestedPreScroll once it has calculated the requested scrolling delta. If it returns true the nested scrolling parent at least partially consumed the scroll and the caller should adjust the amount it scrolls by.

After applying the remainder of the scroll delta the caller should invoke dispatchNestedScroll, passing both the delta consumed and the delta unconsumed. A nested scrolling parent may treat these values differently. See onNestedScroll.

Parameters
axes: Int

Flags consisting of a combination of SCROLL_AXIS_HORIZONTAL and/or SCROLL_AXIS_VERTICAL.

type: Int

the type of input which cause this scroll event

Returns
Boolean

true if a cooperative parent was found and nested scrolling has been enabled for the current gesture.

stopNestedScroll

fun stopNestedScroll(): Unit

stopNestedScroll

Added in 1.0.0
fun stopNestedScroll(type: Int): Unit

Stop a nested scroll in progress for the given input type.

Calling this method when a nested scroll is not currently in progress is harmless.

Parameters
type: Int

the type of input which cause this scroll event

stopScroll

Added in 1.0.0
fun stopScroll(): Unit

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

suppressLayout

Added in 1.1.0
fun suppressLayout(suppress: Boolean): Unit

Tells this RecyclerView to suppress all layout and scroll calls until layout suppression is disabled with a later call to suppressLayout(false). When layout suppression is disabled, a requestLayout() call is sent if requestLayout() was attempted while layout was being suppressed.

In addition to the layout suppression smoothScrollBy, scrollBy, scrollToPosition and smoothScrollToPosition are dropped; TouchEvents and GenericMotionEvents are dropped; onFocusSearchFailed will not be called.

suppressLayout(true) does not prevent app from directly calling scrollToPosition, smoothScrollToPosition.

setAdapter and swapAdapter will automatically stop suppressing.

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

Parameters
suppress: Boolean

true to suppress layout and scroll, false to re-enable.

swapAdapter

Added in 1.0.0
fun swapAdapter(
    adapter: RecyclerView.Adapter?,
    removeAndRecycleExistingViews: Boolean
): Unit

Swaps the current adapter with the provided one. It is similar to setAdapter 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?

The new adapter to set, or null to set no adapter.

removeAndRecycleExistingViews: Boolean

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.

See also
setAdapter

Protected functions

checkLayoutParams

protected fun checkLayoutParams(p: ViewGroup.LayoutParams!): Boolean

dispatchRestoreInstanceState

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

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

dispatchSaveInstanceState

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

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

generateDefaultLayoutParams

protected fun generateDefaultLayoutParams(): ViewGroup.LayoutParams!

generateLayoutParams

protected fun generateLayoutParams(p: ViewGroup.LayoutParams!): ViewGroup.LayoutParams!

getChildDrawingOrder

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

onAttachedToWindow

protected fun onAttachedToWindow(): Unit

onDetachedFromWindow

protected fun onDetachedFromWindow(): Unit

onLayout

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

onMeasure

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

onRequestFocusInDescendants

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

onRestoreInstanceState

protected fun onRestoreInstanceState(state: Parcelable!): Unit

onSaveInstanceState

protected fun onSaveInstanceState(): Parcelable!

onSizeChanged

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

removeDetachedView

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