belongs to Maven artifact com.android.support:recyclerview-v7:28.0.0-alpha1
RecyclerView
public
class
RecyclerView
extends ViewGroup
implements
ScrollingView,
NestedScrollingChild2
java.lang.Object | |||
↳ | android.view.View | ||
↳ | android.view.ViewGroup | ||
↳ | android.support.v7.widget.RecyclerView |
![]() |
![]() |
A flexible view for providing a limited window into a large data set.
Glossary of terms:
- Adapter: A subclass of
RecyclerView.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(int)
. 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 RecyclerView.Adapter
and
RecyclerView.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(int)
). These positions include all changes until the
last layout calculation. You can rely on these positions to be consistent with what user is
currently seeing on the screen. For example, if you have a list of items on the screen and user
asks for the 5th element, you should use these methods as they'll match what user
is seeing.
The other set of position related methods are in the form of
*AdapterPosition*
. (e.g. getAdapterPosition()
,
findViewHolderForAdapterPosition(int)
) You should use these methods when you need to
work with up-to-date adapter positions even if they may not have been reflected to layout yet.
For example, if you want to access the item in the adapter on a ViewHolder click, you should use
getAdapterPosition()
. 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 RecyclerView.LayoutManager
you almost always want to use layout positions whereas when
writing an RecyclerView.Adapter
, you probably want to use adapter positions.
Summary
Nested classes | |
---|---|
class |
RecyclerView.Adapter<VH extends RecyclerView.ViewHolder>
Base class for an Adapter Adapters provide a binding from an app-specific data set to views that are displayed
within a |
class |
RecyclerView.AdapterDataObserver
Observer base class for watching changes to an |
interface |
RecyclerView.ChildDrawingOrderCallback
A callback interface that can be used to alter the drawing order of RecyclerView children. |
class |
RecyclerView.EdgeEffectFactory
EdgeEffectFactory lets you customize the over-scroll edge effect for RecyclerViews. |
class |
RecyclerView.ItemAnimator
This class defines the animations that take place on items as changes are made to the adapter. |
class |
RecyclerView.ItemDecoration
An ItemDecoration allows the application to add a special drawing and layout offset to specific item views from the adapter's data set. |
class |
RecyclerView.LayoutManager
A |
class |
RecyclerView.LayoutParams
|
interface |
RecyclerView.OnChildAttachStateChangeListener
A Listener interface that can be attached to a RecylcerView to get notified whenever a ViewHolder is attached to or detached from RecyclerView. |
class |
RecyclerView.OnFlingListener
This class defines the behavior of fling if the developer wishes to handle it. |
interface |
RecyclerView.OnItemTouchListener
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. |
class |
RecyclerView.OnScrollListener
An OnScrollListener can be added to a RecyclerView to receive messages when a scrolling event has occurred on that RecyclerView. |
class |
RecyclerView.RecycledViewPool
RecycledViewPool lets you share Views between multiple RecyclerViews. |
class |
RecyclerView.Recycler
A Recycler is responsible for managing scrapped or detached item views for reuse. |
interface |
RecyclerView.RecyclerListener
A RecyclerListener can be set on a RecyclerView to receive messages whenever a view is recycled. |
class |
RecyclerView.SimpleOnItemTouchListener
An implementation of |
class |
RecyclerView.SmoothScroller
Base class for smooth scrolling. |
class |
RecyclerView.State
Contains useful information about the current RecyclerView state like target scroll position or view focus. |
class |
RecyclerView.ViewCacheExtension
ViewCacheExtension is a helper class to provide an additional layer of view caching that can be controlled by the developer. |
class |
RecyclerView.ViewHolder
A ViewHolder describes an item view and metadata about its place within the RecyclerView. |
XML attributes | |
---|---|
RecyclerView_layoutManager |
Constants | |
---|---|
int |
HORIZONTAL
|
int |
INVALID_TYPE
|
long |
NO_ID
|
int |
NO_POSITION
|
int |
SCROLL_STATE_DRAGGING
The RecyclerView is currently being dragged by outside input such as user touch input. |
int |
SCROLL_STATE_IDLE
The RecyclerView is not currently scrolling. |
int |
SCROLL_STATE_SETTLING
The RecyclerView is currently animating to a final position while not under outside control. |
int |
TOUCH_SLOP_DEFAULT
Constant for use with |
int |
TOUCH_SLOP_PAGING
Constant for use with |
int |
VERTICAL
|
Inherited constants |
---|
![]()
android.view.ViewGroup
|
![]()
android.view.View
|
Inherited fields |
---|
![]()
android.view.View
|
Public constructors | |
---|---|
RecyclerView(Context context)
|
|
RecyclerView(Context context, AttributeSet attrs)
|
|
RecyclerView(Context context, AttributeSet attrs, int defStyle)
|
Public methods | |
---|---|
void
|
addFocusables(ArrayList<View> views, int direction, int focusableMode)
|
void
|
addItemDecoration(RecyclerView.ItemDecoration decor)
Add an |
void
|
addItemDecoration(RecyclerView.ItemDecoration decor, int index)
Add an |
void
|
addOnChildAttachStateChangeListener(RecyclerView.OnChildAttachStateChangeListener listener)
Register a listener that will be notified whenever a child view is attached to or detached from RecyclerView. |
void
|
addOnItemTouchListener(RecyclerView.OnItemTouchListener listener)
Add an |
void
|
addOnScrollListener(RecyclerView.OnScrollListener listener)
Add a listener that will be notified of any changes in scroll state or position. |
void
|
clearOnChildAttachStateChangeListeners()
Removes all listeners that were added via
|
void
|
clearOnScrollListeners()
Remove all secondary listener that were notified of any changes in scroll state or position. |
int
|
computeHorizontalScrollExtent()
Compute the horizontal extent of the horizontal scrollbar's thumb within the horizontal range. |
int
|
computeHorizontalScrollOffset()
Compute the horizontal offset of the horizontal scrollbar's thumb within the horizontal range. |
int
|
computeHorizontalScrollRange()
Compute the horizontal range that the horizontal scrollbar represents. |
int
|
computeVerticalScrollExtent()
Compute the vertical extent of the vertical scrollbar's thumb within the vertical range. |
int
|
computeVerticalScrollOffset()
Compute the vertical offset of the vertical scrollbar's thumb within the vertical range. |
int
|
computeVerticalScrollRange()
Compute the vertical range that the vertical scrollbar represents. |
boolean
|
dispatchNestedFling(float velocityX, float velocityY, boolean consumed)
|
boolean
|
dispatchNestedPreFling(float velocityX, float velocityY)
|
boolean
|
dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow)
|
boolean
|
dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow, int type)
Dispatch one step of a nested scroll in progress before this view consumes any portion of it. |
boolean
|
dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow, int type)
Dispatch one step of a nested scroll in progress. |
boolean
|
dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow)
|
void
|
draw(Canvas c)
|
boolean
|
drawChild(Canvas canvas, View child, long drawingTime)
|
View
|
findChildViewUnder(float x, float y)
Find the topmost view under the given point. |
View
|
findContainingItemView(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. |
RecyclerView.ViewHolder
|
findContainingViewHolder(View view)
Returns the ViewHolder that contains the given view. |
RecyclerView.ViewHolder
|
findViewHolderForAdapterPosition(int position)
Return the ViewHolder for the item in the given position of the data set. |
RecyclerView.ViewHolder
|
findViewHolderForItemId(long id)
Return the ViewHolder for the item with the given id. |
RecyclerView.ViewHolder
|
findViewHolderForLayoutPosition(int position)
Return the ViewHolder for the item in the given position of the data set as of the latest layout pass. |
RecyclerView.ViewHolder
|
findViewHolderForPosition(int position)
This method was deprecated
in API level 22.1.0.
use |
boolean
|
fling(int velocityX, int velocityY)
Begin a standard fling with an initial velocity along each axis in pixels per second. |
View
|
focusSearch(View focused, int direction)
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
|
generateLayoutParams(AttributeSet attrs)
|
Adapter
|
getAdapter()
Retrieves the previously set adapter or null if no adapter is set. |
int
|
getBaseline()
Return the offset of the RecyclerView's text baseline from the its top boundary. |
int
|
getChildAdapterPosition(View child)
Return the adapter position that the given child view corresponds to. |
long
|
getChildItemId(View child)
Return the stable item id that the given child view corresponds to. |
int
|
getChildLayoutPosition(View child)
Return the adapter position of the given child view as of the latest completed layout pass. |
int
|
getChildPosition(View child)
This method was deprecated
in API level 22.1.0.
use |
RecyclerView.ViewHolder
|
getChildViewHolder(View child)
Retrieve the |
boolean
|
getClipToPadding()
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
|
getCompatAccessibilityDelegate()
Returns the accessibility delegate compatibility implementation used by the RecyclerView. |
void
|
getDecoratedBoundsWithMargins(View view, Rect outBounds)
Returns the bounds of the view including its decoration and margins. |
RecyclerView.EdgeEffectFactory
|
getEdgeEffectFactory()
Retrieves the previously set |
RecyclerView.ItemAnimator
|
getItemAnimator()
Gets the current ItemAnimator for this RecyclerView. |
RecyclerView.ItemDecoration
|
getItemDecorationAt(int index)
Returns an |
int
|
getItemDecorationCount()
Returns the number of |
RecyclerView.LayoutManager
|
getLayoutManager()
Return the |
int
|
getMaxFlingVelocity()
Returns the maximum fling velocity used by this RecyclerView. |
int
|
getMinFlingVelocity()
Returns the minimum velocity to start a fling. |
RecyclerView.OnFlingListener
|
getOnFlingListener()
Get the current |
boolean
|
getPreserveFocusAfterLayout()
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
|
getRecycledViewPool()
Retrieve this RecyclerView's |
int
|
getScrollState()
Return the current scrolling state of the RecyclerView. |
boolean
|
hasFixedSize()
|
boolean
|
hasNestedScrollingParent()
|
boolean
|
hasNestedScrollingParent(int type)
Returns true if this view has a nested scrolling parent for the given input type. |
boolean
|
hasPendingAdapterUpdates()
Returns whether there are pending adapter updates which are not yet applied to the layout. |
void
|
invalidateItemDecorations()
Invalidates all ItemDecorations. |
boolean
|
isAnimating()
Returns true if RecyclerView is currently running some animations. |
boolean
|
isAttachedToWindow()
Returns true if RecyclerView is attached to window. |
boolean
|
isComputingLayout()
Returns whether RecyclerView is currently computing a layout. |
boolean
|
isLayoutFrozen()
Returns true if layout and scroll are frozen. |
boolean
|
isNestedScrollingEnabled()
|
void
|
offsetChildrenHorizontal(int dx)
Offset the bounds of all child views by |
void
|
offsetChildrenVertical(int dy)
Offset the bounds of all child views by |
void
|
onChildAttachedToWindow(View child)
Called when an item view is attached to this RecyclerView. |
void
|
onChildDetachedFromWindow(View child)
Called when an item view is detached from this RecyclerView. |
void
|
onDraw(Canvas c)
|
boolean
|
onGenericMotionEvent(MotionEvent event)
|
boolean
|
onInterceptTouchEvent(MotionEvent e)
|
void
|
onScrollStateChanged(int state)
Called when the scroll state of this RecyclerView changes. |
void
|
onScrolled(int dx, int dy)
Called when the scroll position of this RecyclerView changes. |
boolean
|
onTouchEvent(MotionEvent e)
|
void
|
removeItemDecoration(RecyclerView.ItemDecoration decor)
Remove an |
void
|
removeItemDecorationAt(int index)
Removes the |
void
|
removeOnChildAttachStateChangeListener(RecyclerView.OnChildAttachStateChangeListener listener)
Removes the provided listener from child attached state listeners list. |
void
|
removeOnItemTouchListener(RecyclerView.OnItemTouchListener listener)
Remove an |
void
|
removeOnScrollListener(RecyclerView.OnScrollListener listener)
Remove a listener that was notified of any changes in scroll state or position. |
void
|
requestChildFocus(View child, View focused)
|
boolean
|
requestChildRectangleOnScreen(View child, Rect rect, boolean immediate)
|
void
|
requestDisallowInterceptTouchEvent(boolean disallowIntercept)
|
void
|
requestLayout()
|
void
|
scrollBy(int x, int y)
|
void
|
scrollTo(int x, int y)
|
void
|
scrollToPosition(int position)
Convenience method to scroll to a certain position. |
void
|
sendAccessibilityEventUnchecked(AccessibilityEvent event)
|
void
|
setAccessibilityDelegateCompat(RecyclerViewAccessibilityDelegate accessibilityDelegate)
Sets the accessibility delegate compatibility implementation used by RecyclerView. |
void
|
setAdapter(Adapter adapter)
Set a new adapter to provide child views on demand. |
void
|
setChildDrawingOrderCallback(RecyclerView.ChildDrawingOrderCallback childDrawingOrderCallback)
Sets the |
void
|
setClipToPadding(boolean clipToPadding)
|
void
|
setEdgeEffectFactory(RecyclerView.EdgeEffectFactory edgeEffectFactory)
Set a |
void
|
setHasFixedSize(boolean hasFixedSize)
RecyclerView can perform several optimizations if it can know in advance that RecyclerView's size is not affected by the adapter contents. |
void
|
setItemAnimator(RecyclerView.ItemAnimator animator)
Sets the |
void
|
setItemViewCacheSize(int size)
Set the number of offscreen views to retain before adding them to the potentially shared
|
void
|
setLayoutFrozen(boolean frozen)
Enable or disable layout and scroll. |
void
|
setLayoutManager(RecyclerView.LayoutManager layout)
Set the |
void
|
setNestedScrollingEnabled(boolean enabled)
|
void
|
setOnFlingListener(RecyclerView.OnFlingListener onFlingListener)
Set a |
void
|
setOnScrollListener(RecyclerView.OnScrollListener listener)
This method was deprecated
in API level 22.1.0.
Use |
void
|
setPreserveFocusAfterLayout(boolean preserveFocusAfterLayout)
Set whether the RecyclerView should try to keep the same Item focused after a layout calculation or not. |
void
|
setRecycledViewPool(RecyclerView.RecycledViewPool pool)
Recycled view pools allow multiple RecyclerViews to share a common pool of scrap views. |
void
|
setRecyclerListener(RecyclerView.RecyclerListener listener)
Register a listener that will be notified whenever a child view is recycled. |
void
|
setScrollingTouchSlop(int slopConstant)
Configure the scrolling touch slop for a specific use case. |
void
|
setViewCacheExtension(RecyclerView.ViewCacheExtension extension)
Sets a new |
void
|
smoothScrollBy(int dx, int dy)
Animate a scroll by the given amount of pixels along either axis. |
void
|
smoothScrollBy(int dx, int dy, Interpolator interpolator)
Animate a scroll by the given amount of pixels along either axis. |
void
|
smoothScrollToPosition(int position)
Starts a smooth scroll to an adapter position. |
boolean
|
startNestedScroll(int axes)
|
boolean
|
startNestedScroll(int axes, int type)
Begin a nestable scroll operation along the given axes, for the given input type. |
void
|
stopNestedScroll()
|
void
|
stopNestedScroll(int type)
Stop a nested scroll in progress for the given input type. |
void
|
stopScroll()
Stop any current scroll in progress, such as one started by
|
void
|
swapAdapter(Adapter adapter, boolean removeAndRecycleExistingViews)
Swaps the current adapter with the provided one. |
Protected methods | |
---|---|
boolean
|
checkLayoutParams(ViewGroup.LayoutParams p)
|
void
|
dispatchRestoreInstanceState(SparseArray<Parcelable> container)
Override to prevent thawing of any views created by the adapter. |
void
|
dispatchSaveInstanceState(SparseArray<Parcelable> container)
Override to prevent freezing of any views created by the adapter. |
ViewGroup.LayoutParams
|
generateDefaultLayoutParams()
|
ViewGroup.LayoutParams
|
generateLayoutParams(ViewGroup.LayoutParams p)
|
int
|
getChildDrawingOrder(int childCount, int i)
|
void
|
onAttachedToWindow()
|
void
|
onDetachedFromWindow()
|
void
|
onLayout(boolean changed, int l, int t, int r, int b)
|
void
|
onMeasure(int widthSpec, int heightSpec)
|
boolean
|
onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect)
|
void
|
onRestoreInstanceState(Parcelable state)
|
Parcelable
|
onSaveInstanceState()
|
void
|
onSizeChanged(int w, int h, int oldw, int oldh)
|
void
|
removeDetachedView(View child, boolean animate)
|
Inherited methods | |
---|---|
![]()
android.view.ViewGroup
| |
![]()
android.view.View
| |
![]()
java.lang.Object
| |
![]()
android.view.ViewParent
| |
![]()
android.view.ViewManager
| |
![]()
android.graphics.drawable.Drawable.Callback
| |
![]()
android.view.KeyEvent.Callback
| |
![]()
android.view.accessibility.AccessibilityEventSource
| |
![]()
android.support.v4.view.ScrollingView
| |
![]()
android.support.v4.view.NestedScrollingChild2
| |
![]()
android.support.v4.view.NestedScrollingChild
|
XML attributes
RecyclerView_layoutManager
Constants
SCROLL_STATE_DRAGGING
int SCROLL_STATE_DRAGGING
The RecyclerView is currently being dragged by outside input such as user touch input.
See also:
Constant Value: 1 (0x00000001)
SCROLL_STATE_IDLE
int SCROLL_STATE_IDLE
The RecyclerView is not currently scrolling.
See also:
Constant Value: 0 (0x00000000)
SCROLL_STATE_SETTLING
int SCROLL_STATE_SETTLING
The RecyclerView is currently animating to a final position while not under outside control.
See also:
Constant Value: 2 (0x00000002)
TOUCH_SLOP_DEFAULT
int TOUCH_SLOP_DEFAULT
Constant for use with setScrollingTouchSlop(int)
. Indicates
that the RecyclerView should use the standard touch slop for smooth,
continuous scrolling.
Constant Value: 0 (0x00000000)
TOUCH_SLOP_PAGING
int TOUCH_SLOP_PAGING
Constant for use with setScrollingTouchSlop(int)
. Indicates
that the RecyclerView should use the standard touch slop for scrolling
widgets that snap to a page or other coarse-grained barrier.
Constant Value: 1 (0x00000001)
Public constructors
RecyclerView
RecyclerView (Context context, AttributeSet attrs)
Parameters | |
---|---|
context |
Context |
attrs |
AttributeSet |
RecyclerView
RecyclerView (Context context, AttributeSet attrs, int defStyle)
Parameters | |
---|---|
context |
Context |
attrs |
AttributeSet |
defStyle |
int |
Public methods
addFocusables
void addFocusables (ArrayList<View> views, int direction, int focusableMode)
Parameters | |
---|---|
views |
ArrayList |
direction |
int |
focusableMode |
int |
addItemDecoration
void addItemDecoration (RecyclerView.ItemDecoration decor)
Add an RecyclerView.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
void addItemDecoration (RecyclerView.ItemDecoration decor, int index)
Add an RecyclerView.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
void addOnChildAttachStateChangeListener (RecyclerView.OnChildAttachStateChangeListener listener)
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
void addOnItemTouchListener (RecyclerView.OnItemTouchListener listener)
Add an RecyclerView.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(RecyclerView, MotionEvent)
its
onTouchEvent(RecyclerView, MotionEvent)
method will be called
for each incoming MotionEvent until the end of the gesture.
Parameters | |
---|---|
listener |
RecyclerView.OnItemTouchListener : Listener to add |
See also:
addOnScrollListener
void addOnScrollListener (RecyclerView.OnScrollListener listener)
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
|
clearOnChildAttachStateChangeListeners
void clearOnChildAttachStateChangeListeners ()
Removes all listeners that were added via
addOnChildAttachStateChangeListener(OnChildAttachStateChangeListener)
.
clearOnScrollListeners
void clearOnScrollListeners ()
Remove all secondary listener that were notified of any changes in scroll state or position.
computeHorizontalScrollExtent
int computeHorizontalScrollExtent ()
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(RecyclerView.State)
in your
LayoutManager.
Returns | |
---|---|
int |
The horizontal extent of the scrollbar's thumb |
computeHorizontalScrollOffset
int computeHorizontalScrollOffset ()
Compute the horizontal offset of the horizontal scrollbar's thumb within the horizontal range. This value is used to compute the length of the thumb within the scrollbar's track.
The range is expressed in arbitrary units that must be the same as the units used by
computeHorizontalScrollRange()
and computeHorizontalScrollExtent()
.
Default implementation returns 0.
If you want to support scroll bars, override
computeHorizontalScrollOffset(RecyclerView.State)
in your
LayoutManager.
Returns | |
---|---|
int |
The horizontal offset of the scrollbar's thumb |
See also:
computeHorizontalScrollRange
int computeHorizontalScrollRange ()
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(RecyclerView.State)
in your
LayoutManager.
Returns | |
---|---|
int |
The total horizontal range represented by the vertical scrollbar |
computeVerticalScrollExtent
int computeVerticalScrollExtent ()
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(RecyclerView.State)
in your
LayoutManager.
Returns | |
---|---|
int |
The vertical extent of the scrollbar's thumb |
computeVerticalScrollOffset
int computeVerticalScrollOffset ()
Compute the vertical offset of the vertical scrollbar's thumb within the vertical range. This value is used to compute the length of the thumb within the scrollbar's track.
The range is expressed in arbitrary units that must be the same as the units used by
computeVerticalScrollRange()
and computeVerticalScrollExtent()
.
Default implementation returns 0.
If you want to support scroll bars, override
computeVerticalScrollOffset(RecyclerView.State)
in your
LayoutManager.
Returns | |
---|---|
int |
The vertical offset of the scrollbar's thumb |
See also:
computeVerticalScrollRange
int computeVerticalScrollRange ()
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(RecyclerView.State)
in your
LayoutManager.
Returns | |
---|---|
int |
The total vertical range represented by the vertical scrollbar |
dispatchNestedFling
boolean dispatchNestedFling (float velocityX, float velocityY, boolean consumed)
Parameters | |
---|---|
velocityX |
float |
velocityY |
float |
consumed |
boolean |
Returns | |
---|---|
boolean |
dispatchNestedPreFling
boolean dispatchNestedPreFling (float velocityX, float velocityY)
Parameters | |
---|---|
velocityX |
float |
velocityY |
float |
Returns | |
---|---|
boolean |
dispatchNestedPreScroll
boolean dispatchNestedPreScroll (int dx, int dy, int[] consumed, int[] offsetInWindow)
Parameters | |
---|---|
dx |
int |
dy |
int |
consumed |
int |
offsetInWindow |
int |
Returns | |
---|---|
boolean |
dispatchNestedPreScroll
boolean dispatchNestedPreScroll (int dx, int dy, int[] consumed, int[] offsetInWindow, int type)
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 |
int : Output. If not null, consumed[0] will contain the consumed component of dx
and consumed[1] the consumed dy. |
offsetInWindow |
int : 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
boolean dispatchNestedScroll (int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow, int type)
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 |
int : 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
boolean dispatchNestedScroll (int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow)
Parameters | |
---|---|
dxConsumed |
int |
dyConsumed |
int |
dxUnconsumed |
int |
dyUnconsumed |
int |
offsetInWindow |
int |
Returns | |
---|---|
boolean |
drawChild
boolean drawChild (Canvas canvas, View child, long drawingTime)
Parameters | |
---|---|
canvas |
Canvas |
child |
View |
drawingTime |
long |
Returns | |
---|---|
boolean |
findChildViewUnder
View findChildViewUnder (float x, float y)
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
View findContainingItemView (View view)
Traverses the ancestors of the given view and returns the item view that contains it and
also a direct child of the RecyclerView. This returned view can be used to get the
ViewHolder by calling getChildViewHolder(View)
.
Parameters | |
---|---|
view |
View : The view that is a descendant of the RecyclerView. |
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
RecyclerView.ViewHolder findContainingViewHolder (View view)
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
RecyclerView.ViewHolder findViewHolderForAdapterPosition (int position)
Return the ViewHolder for the item in the given position of the data set. Unlike
findViewHolderForLayoutPosition(int)
this method takes into account any pending
adapter changes that may not be reflected to the layout yet. On the other hand, if
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
RecyclerView.ViewHolder findViewHolderForItemId (long id)
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
RecyclerView.ViewHolder findViewHolderForLayoutPosition (int position)
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
#getAdapterPosition()
to get the current adapter position of a ViewHolder.
When the ItemAnimator is running a change animation, there might be 2 ViewHolders with the same layout position representing the same Item. In this case, the updated ViewHolder will be returned.
Parameters | |
---|---|
position |
int : The position of the item in the data set of the adapter |
Returns | |
---|---|
RecyclerView.ViewHolder |
The ViewHolder at position or null if there is no such item
|
findViewHolderForPosition
RecyclerView.ViewHolder findViewHolderForPosition (int position)
This method was deprecated
in API level 22.1.0.
use findViewHolderForLayoutPosition(int)
or
findViewHolderForAdapterPosition(int)
Parameters | |
---|---|
position |
int |
Returns | |
---|---|
RecyclerView.ViewHolder |
fling
boolean fling (int velocityX, int velocityY)
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
View focusSearch (View focused, int direction)
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(View, int, Recycler, State)
to layout more Views
in the focus search direction. If LayoutManager adds a View that matches the
focus search criteria, it will be returned as the focus search result. Otherwise,
RecyclerView will call parent to handle the focus search like a regular ViewGroup.
When the direction is 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(View, int, Recycler, State)
before running a
focus search with the original (relative) direction. This allows RecyclerView to provide
better candidates to the focus search while still allowing the view system to take focus from
the RecyclerView and give it to a more suitable child if such child exists.
Parameters | |
---|---|
focused |
View : The view that currently has focus |
direction |
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
ViewGroup.LayoutParams generateLayoutParams (AttributeSet attrs)
Parameters | |
---|---|
attrs |
AttributeSet |
Returns | |
---|---|
ViewGroup.LayoutParams |
getAdapter
Adapter getAdapter ()
Retrieves the previously set adapter or null if no adapter is set.
Returns | |
---|---|
Adapter |
The previously set adapter |
See also:
getBaseline
int getBaseline ()
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
int getChildAdapterPosition (View child)
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
long getChildItemId (View child)
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
int getChildLayoutPosition (View child)
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
int getChildPosition (View child)
This method was deprecated
in API level 22.1.0.
use getChildAdapterPosition(View)
or
getChildLayoutPosition(View)
.
Parameters | |
---|---|
child |
View |
Returns | |
---|---|
int |
getChildViewHolder
RecyclerView.ViewHolder getChildViewHolder (View child)
Retrieve the RecyclerView.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
boolean getClipToPadding ()
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.
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
RecyclerViewAccessibilityDelegate getCompatAccessibilityDelegate ()
Returns the accessibility delegate compatibility implementation used by the RecyclerView.
Returns | |
---|---|
RecyclerViewAccessibilityDelegate |
An instance of AccessibilityDelegateCompat used by RecyclerView |
getDecoratedBoundsWithMargins
void getDecoratedBoundsWithMargins (View view, Rect outBounds)
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
RecyclerView.EdgeEffectFactory getEdgeEffectFactory ()
Retrieves the previously set RecyclerView.EdgeEffectFactory
or the default factory if nothing
was set.
Returns | |
---|---|
RecyclerView.EdgeEffectFactory |
The previously set RecyclerView.EdgeEffectFactory |
See also:
getItemAnimator
RecyclerView.ItemAnimator getItemAnimator ()
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
RecyclerView.ItemDecoration getItemDecorationAt (int index)
Returns an RecyclerView.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 | |
---|---|
IndexOutOfBoundsException |
on invalid index |
getItemDecorationCount
int getItemDecorationCount ()
Returns the number of RecyclerView.ItemDecoration
currently added to this RecyclerView.
Returns | |
---|---|
int |
number of ItemDecorations currently added added to this RecyclerView. |
getLayoutManager
RecyclerView.LayoutManager getLayoutManager ()
Return the RecyclerView.LayoutManager
currently responsible for
layout policy for this RecyclerView.
Returns | |
---|---|
RecyclerView.LayoutManager |
The currently bound LayoutManager |
getMaxFlingVelocity
int getMaxFlingVelocity ()
Returns the maximum fling velocity used by this RecyclerView.
Returns | |
---|---|
int |
The maximum fling velocity used by this RecyclerView. |
getMinFlingVelocity
int getMinFlingVelocity ()
Returns the minimum velocity to start a fling.
Returns | |
---|---|
int |
The minimum velocity to start a fling |
getOnFlingListener
RecyclerView.OnFlingListener getOnFlingListener ()
Get the current RecyclerView.OnFlingListener
from this RecyclerView
.
Returns | |
---|---|
RecyclerView.OnFlingListener |
The RecyclerView.OnFlingListener instance currently set (can be null).
|
getPreserveFocusAfterLayout
boolean getPreserveFocusAfterLayout ()
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. |
See also:
getRecycledViewPool
RecyclerView.RecycledViewPool getRecycledViewPool ()
Retrieve this RecyclerView's RecyclerView.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. |
See also:
getScrollState
int getScrollState ()
Return the current scrolling state of the RecyclerView.
Returns | |
---|---|
int |
SCROLL_STATE_IDLE , SCROLL_STATE_DRAGGING or
SCROLL_STATE_SETTLING
|
hasFixedSize
boolean hasFixedSize ()
Returns | |
---|---|
boolean |
true if the app has specified that changes in adapter content cannot change the size of the RecyclerView itself. |
hasNestedScrollingParent
boolean hasNestedScrollingParent ()
Returns | |
---|---|
boolean |
hasNestedScrollingParent
boolean hasNestedScrollingParent (int type)
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
boolean hasPendingAdapterUpdates ()
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