public class RecyclerView extends ViewGroup implements ScrollingView, NestedScrollingChild
RecyclerView.Adapter
responsible for providing views
that represent items in a data set.ViewGroup.getChildAt(int)
. Contrast with Position.
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:
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. RecyclerView.ViewHolder.getLayoutPosition()
,
findViewHolderForLayoutPosition(int)
). These positions include all changes until the
last layout calculation. You can rely on these positions to be consistent with what user is
currently seeing on the screen. For example, if you have a list of items on the screen and user
asks for the 5th element, you should use these methods as they'll match what user
is seeing.
The other set of position related methods are in the form of
*AdapterPosition*
. (e.g. RecyclerView.ViewHolder.getAdapterPosition()
,
findViewHolderForAdapterPosition(int)
) You should use these methods when you need to
work with up-to-date adapter positions even if they may not have been reflected to layout yet.
For example, if you want to access the item in the adapter on a ViewHolder click, you should use
RecyclerView.ViewHolder.getAdapterPosition()
. Beware that these methods may not be able to calculate
adapter positions if RecyclerView.Adapter.notifyDataSetChanged()
has been called and new layout has
not yet been calculated. For this reasons, you should carefully handle NO_POSITION
or
null
results from these methods.
When writing a RecyclerView.LayoutManager
you almost always want to use layout positions whereas when
writing an RecyclerView.Adapter
, you probably want to use adapter positions.
Modifier and Type | Class and Description |
---|---|
static 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
RecyclerView . |
static class |
RecyclerView.AdapterDataObserver
Observer base class for watching changes to an
RecyclerView.Adapter . |
static interface |
RecyclerView.ChildDrawingOrderCallback
A callback interface that can be used to alter the drawing order of RecyclerView children.
|
static class |
RecyclerView.ItemAnimator
This class defines the animations that take place on items as changes are made
to the adapter.
|
static 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.
|
static class |
RecyclerView.LayoutManager
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. |
static class |
RecyclerView.LayoutParams
LayoutParams subclass for children of
RecyclerView . |
static 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.
|
static class |
RecyclerView.OnFlingListener
This class defines the behavior of fling if the developer wishes to handle it.
|
static 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.
|
static class |
RecyclerView.OnScrollListener
An OnScrollListener can be added to a RecyclerView to receive messages when a scrolling event
has occurred on that RecyclerView.
|
static 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.
|
static interface |
RecyclerView.RecyclerListener
A RecyclerListener can be set on a RecyclerView to receive messages whenever
a view is recycled.
|
static class |
RecyclerView.SavedState
This is public so that the CREATOR can be access on cold launch.
|
static class |
RecyclerView.SimpleOnItemTouchListener
An implementation of
RecyclerView.OnItemTouchListener that has empty method bodies and
default return values. |
static class |
RecyclerView.SmoothScroller
Base class for smooth scrolling.
|
static class |
RecyclerView.State
Contains useful information about the current RecyclerView state like target scroll
position or view focus.
|
static class |
RecyclerView.ViewCacheExtension
ViewCacheExtension is a helper class to provide an additional layer of view caching that can
be controlled by the developer.
|
static class |
RecyclerView.ViewHolder
A ViewHolder describes an item view and metadata about its place within the RecyclerView.
|
ViewGroup.MarginLayoutParams, ViewGroup.OnHierarchyChangeListener
View.AccessibilityDelegate, View.BaseSavedState, View.DragShadowBuilder, View.DrawingCacheQuality, View.FindViewFlags, View.FocusableMode, View.FocusDirection, View.FocusRealDirection, View.LayoutDir, View.MeasureSpec, View.OnApplyWindowInsetsListener, View.OnAttachStateChangeListener, View.OnClickListener, View.OnContextClickListener, View.OnCreateContextMenuListener, View.OnDragListener, View.OnFocusChangeListener, View.OnGenericMotionListener, View.OnHoverListener, View.OnKeyListener, View.OnLayoutChangeListener, View.OnLongClickListener, View.OnScrollChangeListener, View.OnSystemUiVisibilityChangeListener, View.OnTouchListener, View.ResolvedLayoutDir, View.ScrollBarStyle, View.ScrollIndicators, View.TextAlignment, View.Visibility
Modifier and Type | Field and Description |
---|---|
static int |
HORIZONTAL |
static int |
INVALID_TYPE |
static long |
NO_ID |
static int |
NO_POSITION |
static int |
SCROLL_STATE_DRAGGING
The RecyclerView is currently being dragged by outside input such as user touch input.
|
static int |
SCROLL_STATE_IDLE
The RecyclerView is not currently scrolling.
|
static int |
SCROLL_STATE_SETTLING
The RecyclerView is currently animating to a final position while not under
outside control.
|
static int |
TOUCH_SLOP_DEFAULT
Constant for use with
setScrollingTouchSlop(int) . |
static int |
TOUCH_SLOP_PAGING
Constant for use with
setScrollingTouchSlop(int) . |
static int |
VERTICAL |
CLIP_TO_PADDING_MASK, DEBUG_DRAW, FLAG_DISALLOW_INTERCEPT, FLAG_SUPPORT_STATIC_TRANSFORMATIONS, FLAG_USE_CHILD_DRAWING_ORDER, FOCUS_AFTER_DESCENDANTS, FOCUS_BEFORE_DESCENDANTS, FOCUS_BLOCK_DESCENDANTS, LAYOUT_MODE_CLIP_BOUNDS, LAYOUT_MODE_DEFAULT, LAYOUT_MODE_OPTICAL_BOUNDS, mDisappearingChildren, mGroupFlags, mOnHierarchyChangeListener, mPersistentDrawingCache, PERSISTENT_ALL_CACHES, PERSISTENT_ANIMATION_CACHE, PERSISTENT_NO_CACHE, PERSISTENT_SCROLLING_CACHE
ACCESSIBILITY_CURSOR_POSITION_UNDEFINED, ACCESSIBILITY_LIVE_REGION_ASSERTIVE, ACCESSIBILITY_LIVE_REGION_NONE, ACCESSIBILITY_LIVE_REGION_POLITE, ALPHA, DEBUG_LAYOUT_PROPERTY, DRAG_FLAG_GLOBAL, DRAG_FLAG_GLOBAL_PERSISTABLE_URI_PERMISSION, DRAG_FLAG_GLOBAL_PREFIX_URI_PERMISSION, DRAG_FLAG_GLOBAL_URI_READ, DRAG_FLAG_GLOBAL_URI_WRITE, DRAG_FLAG_OPAQUE, DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_HIGH, DRAWING_CACHE_QUALITY_LOW, EMPTY_STATE_SET, ENABLED_FOCUSED_SELECTED_STATE_SET, ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_FOCUSED_STATE_SET, ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, ENABLED_SELECTED_STATE_SET, ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_STATE_SET, ENABLED_WINDOW_FOCUSED_STATE_SET, FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS, FIND_VIEWS_WITH_CONTENT_DESCRIPTION, FIND_VIEWS_WITH_TEXT, FOCUS_BACKWARD, FOCUS_DOWN, FOCUS_FORWARD, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_UP, FOCUSABLES_ALL, FOCUSABLES_TOUCH_MODE, FOCUSED_SELECTED_STATE_SET, FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, FOCUSED_STATE_SET, FOCUSED_WINDOW_FOCUSED_STATE_SET, GONE, HAPTIC_FEEDBACK_ENABLED, IMPORTANT_FOR_ACCESSIBILITY_AUTO, IMPORTANT_FOR_ACCESSIBILITY_NO, IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS, IMPORTANT_FOR_ACCESSIBILITY_YES, INVISIBLE, KEEP_SCREEN_ON, LAYER_TYPE_HARDWARE, LAYER_TYPE_NONE, LAYER_TYPE_SOFTWARE, LAYOUT_DIRECTION_INHERIT, LAYOUT_DIRECTION_LOCALE, LAYOUT_DIRECTION_LTR, LAYOUT_DIRECTION_RTL, LAYOUT_DIRECTION_UNDEFINED, mAttributes, mBottom, mCachingFailed, mContext, mCurrentAnimation, mDebugViewAttributes, MEASURED_HEIGHT_STATE_SHIFT, MEASURED_SIZE_MASK, MEASURED_STATE_MASK, MEASURED_STATE_TOO_SMALL, mInputEventConsistencyVerifier, mLayoutParams, mLeft, mPaddingBottom, mPaddingLeft, mPaddingRight, mPaddingTop, mParent, mRight, mScrollX, mScrollY, mTag, mTop, mUserPaddingBottom, mUserPaddingLeft, mUserPaddingRight, NAVIGATION_BAR_TRANSIENT, NAVIGATION_BAR_TRANSLUCENT, NAVIGATION_BAR_TRANSPARENT, NAVIGATION_BAR_UNHIDE, OVER_SCROLL_ALWAYS, OVER_SCROLL_IF_CONTENT_SCROLLS, OVER_SCROLL_NEVER, PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET, PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_SELECTED_STATE_SET, PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_STATE_SET, PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_SELECTED_STATE_SET, PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_STATE_SET, PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_SELECTED_STATE_SET, PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_STATE_SET, PRESSED_WINDOW_FOCUSED_STATE_SET, PUBLIC_STATUS_BAR_VISIBILITY_MASK, ROTATION, ROTATION_X, ROTATION_Y, SCALE_X, SCALE_Y, SCREEN_STATE_OFF, SCREEN_STATE_ON, SCROLL_AXIS_HORIZONTAL, SCROLL_AXIS_NONE, SCROLL_AXIS_VERTICAL, SCROLL_INDICATOR_BOTTOM, SCROLL_INDICATOR_END, SCROLL_INDICATOR_LEFT, SCROLL_INDICATOR_RIGHT, SCROLL_INDICATOR_START, SCROLL_INDICATOR_TOP, SCROLLBAR_POSITION_DEFAULT, SCROLLBAR_POSITION_LEFT, SCROLLBAR_POSITION_RIGHT, SCROLLBARS_INSIDE_INSET, SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_OUTSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY, SELECTED_STATE_SET, SELECTED_WINDOW_FOCUSED_STATE_SET, SOUND_EFFECTS_ENABLED, sPreserveMarginParamsInLayoutParamConversion, STATUS_BAR_DISABLE_BACK, STATUS_BAR_DISABLE_CLOCK, STATUS_BAR_DISABLE_EXPAND, STATUS_BAR_DISABLE_HOME, STATUS_BAR_DISABLE_NOTIFICATION_ALERTS, STATUS_BAR_DISABLE_NOTIFICATION_ICONS, STATUS_BAR_DISABLE_NOTIFICATION_TICKER, STATUS_BAR_DISABLE_RECENT, STATUS_BAR_DISABLE_SEARCH, STATUS_BAR_DISABLE_SYSTEM_INFO, STATUS_BAR_HIDDEN, STATUS_BAR_TRANSIENT, STATUS_BAR_TRANSLUCENT, STATUS_BAR_TRANSPARENT, STATUS_BAR_UNHIDE, STATUS_BAR_VISIBLE, SYSTEM_UI_CLEARABLE_FLAGS, SYSTEM_UI_FLAG_FULLSCREEN, SYSTEM_UI_FLAG_HIDE_NAVIGATION, SYSTEM_UI_FLAG_IMMERSIVE, SYSTEM_UI_FLAG_IMMERSIVE_STICKY, SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN, SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION, SYSTEM_UI_FLAG_LAYOUT_STABLE, SYSTEM_UI_FLAG_LIGHT_STATUS_BAR, SYSTEM_UI_FLAG_LOW_PROFILE, SYSTEM_UI_FLAG_VISIBLE, SYSTEM_UI_LAYOUT_FLAGS, SYSTEM_UI_TRANSPARENT, TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_GRAVITY, TEXT_ALIGNMENT_INHERIT, TEXT_ALIGNMENT_TEXT_END, TEXT_ALIGNMENT_TEXT_START, TEXT_ALIGNMENT_VIEW_END, TEXT_ALIGNMENT_VIEW_START, TEXT_DIRECTION_ANY_RTL, TEXT_DIRECTION_FIRST_STRONG, TEXT_DIRECTION_FIRST_STRONG_LTR, TEXT_DIRECTION_FIRST_STRONG_RTL, TEXT_DIRECTION_INHERIT, TEXT_DIRECTION_LOCALE, TEXT_DIRECTION_LTR, TEXT_DIRECTION_RTL, TRANSLATION_X, TRANSLATION_Y, TRANSLATION_Z, VIEW_LOG_TAG, VISIBLE, WINDOW_FOCUSED_STATE_SET, X, Y, Z
Constructor and Description |
---|
RecyclerView(Context context) |
RecyclerView(Context context,
AttributeSet attrs) |
RecyclerView(Context context,
AttributeSet attrs,
int defStyle) |
Modifier and Type | Method and Description |
---|---|
void |
addFocusables(ArrayList<View> views,
int direction,
int focusableMode)
Adds any focusable views that are descendants of this view (possibly
including this view if it is focusable itself) to views.
|
void |
addItemDecoration(RecyclerView.ItemDecoration decor)
Add an
RecyclerView.ItemDecoration to this RecyclerView. |
void |
addItemDecoration(RecyclerView.ItemDecoration decor,
int index)
Add an
RecyclerView.ItemDecoration to this RecyclerView. |
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
RecyclerView.OnItemTouchListener to intercept touch events before they are dispatched
to child views or this view's standard scrolling behavior. |
void |
addOnScrollListener(RecyclerView.OnScrollListener listener)
Add a listener that will be notified of any changes in scroll state or position.
|
protected boolean |
checkLayoutParams(ViewGroup.LayoutParams p) |
void |
clearOnChildAttachStateChangeListeners()
Removes all listeners that were added via
addOnChildAttachStateChangeListener(OnChildAttachStateChangeListener) . |
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)
Dispatch a fling to a nested scrolling parent.
|
boolean |
dispatchNestedPreFling(float velocityX,
float velocityY)
Dispatch a fling to a nested scrolling parent before it is processed by this view.
|
boolean |
dispatchNestedPreScroll(int dx,
int dy,
int[] consumed,
int[] offsetInWindow)
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)
Dispatch one step of a nested scroll in progress.
|
protected void |
dispatchRestoreInstanceState(SparseArray<Parcelable> container)
Override to prevent thawing of any views created by the adapter.
|
protected void |
dispatchSaveInstanceState(SparseArray<Parcelable> container)
Override to prevent freezing of any views created by the adapter.
|
void |
draw(Canvas c)
Manually render this view (and all of its children) to the given Canvas.
|
boolean |
drawChild(Canvas canvas,
View child,
long drawingTime)
Draw one child of this View Group.
|
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)
Deprecated.
|
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.
|
protected ViewGroup.LayoutParams |
generateDefaultLayoutParams()
Returns a set of default layout parameters.
|
ViewGroup.LayoutParams |
generateLayoutParams(AttributeSet attrs)
Returns a new set of layout parameters based on the supplied attributes set.
|
protected ViewGroup.LayoutParams |
generateLayoutParams(ViewGroup.LayoutParams p)
Returns a safe set of layout parameters based on the supplied layout params.
|
RecyclerView.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.
|
protected int |
getChildDrawingOrder(int childCount,
int i)
Returns the index of the child to draw for this iteration.
|
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)
Deprecated.
|
RecyclerView.ViewHolder |
getChildViewHolder(View child)
Retrieve the
RecyclerView.ViewHolder for the given child view. |
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.ItemAnimator |
getItemAnimator()
Gets the current ItemAnimator for this RecyclerView.
|
RecyclerView.LayoutManager |
getLayoutManager()
Return the
RecyclerView.LayoutManager currently responsible for
layout policy for this RecyclerView. |
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
RecyclerView.OnFlingListener from this RecyclerView . |
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
RecyclerView.RecycledViewPool . |
int |
getScrollState()
Return the current scrolling state of the RecyclerView.
|
boolean |
hasFixedSize() |
boolean |
hasNestedScrollingParent()
Returns true if this view has a nested scrolling parent.
|
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()
Returns true if nested scrolling is enabled for this view.
|
void |
offsetChildrenHorizontal(int dx)
Offset the bounds of all child views by
dx pixels. |
void |
offsetChildrenVertical(int dy)
Offset the bounds of all child views by
dy pixels. |
protected void |
onAttachedToWindow()
This is called when the view is attached to a window.
|
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.
|
protected void |
onDetachedFromWindow()
This is called when the view is detached from a window.
|
void |
onDraw(Canvas c)
Implement this to do your drawing.
|
boolean |
onGenericMotionEvent(MotionEvent event)
Implement this method to handle generic motion events.
|
boolean |
onInterceptTouchEvent(MotionEvent e)
Implement this method to intercept all touch screen motion events.
|
protected void |
onLayout(boolean changed,
int l,
int t,
int r,
int b)
Called from layout when this view should
assign a size and position to each of its children.
|
protected void |
onMeasure(int widthSpec,
int heightSpec)
Measure the view and its content to determine the measured width and the
measured height.
|
protected boolean |
onRequestFocusInDescendants(int direction,
Rect previouslyFocusedRect)
Look for a descendant to call
View.requestFocus() on. |
protected void |
onRestoreInstanceState(Parcelable state)
Hook allowing a view to re-apply a representation of its internal state that had previously
been generated by
View.onSaveInstanceState() . |
protected Parcelable |
onSaveInstanceState()
Hook allowing a view to generate a representation of its internal state
that can later be used to create a new instance with that same state.
|
void |
onScrolled(int dx,
int dy)
Called when the scroll position of this RecyclerView changes.
|
void |
onScrollStateChanged(int state)
Called when the scroll state of this RecyclerView changes.
|
protected void |
onSizeChanged(int w,
int h,
int oldw,
int oldh)
This is called during layout when the size of this view has changed.
|
boolean |
onTouchEvent(MotionEvent e)
Implement this method to handle touch screen motion events.
|
protected void |
removeDetachedView(View child,
boolean animate)
Finishes the removal of a detached view.
|
void |
removeItemDecoration(RecyclerView.ItemDecoration decor)
Remove an
RecyclerView.ItemDecoration from this RecyclerView. |
void |
removeOnChildAttachStateChangeListener(RecyclerView.OnChildAttachStateChangeListener listener)
Removes the provided listener from child attached state listeners list.
|
void |
removeOnItemTouchListener(RecyclerView.OnItemTouchListener listener)
Remove an
RecyclerView.OnItemTouchListener . |
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)
Called when a child of this parent wants focus
|
boolean |
requestChildRectangleOnScreen(View child,
Rect rect,
boolean immediate)
Called when a child of this group wants a particular rectangle to be
positioned onto the screen.
|
void |
requestDisallowInterceptTouchEvent(boolean disallowIntercept)
Called when a child does not want this parent and its ancestors to
intercept touch events with
ViewGroup.onInterceptTouchEvent(MotionEvent) . |
void |
requestLayout()
Call this when something has changed which has invalidated the
layout of this view.
|
void |
scrollBy(int x,
int y)
Move the scrolled position of your view.
|
void |
scrollTo(int x,
int y)
Set the scrolled position of your view.
|
void |
scrollToPosition(int position)
Convenience method to scroll to a certain position.
|
void |
sendAccessibilityEventUnchecked(AccessibilityEvent event)
This method behaves exactly as
View.sendAccessibilityEvent(int) but
takes as an argument an empty AccessibilityEvent and does not
perform a check whether accessibility is enabled. |
void |
setAccessibilityDelegateCompat(RecyclerViewAccessibilityDelegate accessibilityDelegate)
Sets the accessibility delegate compatibility implementation used by RecyclerView.
|
void |
setAdapter(RecyclerView.Adapter adapter)
Set a new adapter to provide child views on demand.
|
void |
setChildDrawingOrderCallback(RecyclerView.ChildDrawingOrderCallback childDrawingOrderCallback)
Sets the
RecyclerView.ChildDrawingOrderCallback to be used for drawing children. |
void |
setClipToPadding(boolean clipToPadding)
Sets whether this ViewGroup will clip its children to its padding and resize (but not
clip) any EdgeEffect to the padded region, if padding is present.
|
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
RecyclerView.ItemAnimator that will handle animations involving changes
to the items in this RecyclerView. |
void |
setItemViewCacheSize(int size)
Set the number of offscreen views to retain before adding them to the potentially shared
recycled view pool . |
void |
setLayoutFrozen(boolean frozen)
Enable or disable layout and scroll.
|
void |
setLayoutManager(RecyclerView.LayoutManager layout)
Set the
RecyclerView.LayoutManager that this RecyclerView will use. |
void |
setNestedScrollingEnabled(boolean enabled)
Enable or disable nested scrolling for this view.
|
void |
setOnFlingListener(RecyclerView.OnFlingListener onFlingListener)
Set a
RecyclerView.OnFlingListener for this RecyclerView . |
void |
setOnScrollListener(RecyclerView.OnScrollListener listener)
Deprecated.
|
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
RecyclerView.ViewCacheExtension to be used by the Recycler. |
void |
smoothScrollBy(int dx,
int dy)
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)
Begin a nestable scroll operation along the given axes.
|
void |
stopNestedScroll()
Stop a nested scroll in progress.
|
void |
stopScroll()
Stop any current scroll in progress, such as one started by
smoothScrollBy(int, int) , fling(int, int) or a touch-initiated fling. |
void |
swapAdapter(RecyclerView.Adapter adapter,
boolean removeAndRecycleExistingViews)
Swaps the current adapter with the provided one.
|
addChildrenForAccessibility, addStatesFromChildren, addTouchables, addTransientView, addView, addView, addView, addView, addView, addViewInLayout, addViewInLayout, attachLayoutAnimationParameters, attachViewToParent, bringChildToFront, buildTouchDispatchChildList, canAnimate, captureTransitioningViews, childDrawableStateChanged, childHasTransientStateChanged, cleanupLayoutState, clearChildFocus, clearDisappearingChildren, clearFocus, createSnapshot, damageChild, damageChildDeferred, damageChildInParent, debug, detachAllViewsFromParent, detachViewFromParent, detachViewFromParent, detachViewsFromParent, dispatchActivityResult, dispatchApplyWindowInsets, dispatchConfigurationChanged, dispatchDisplayHint, dispatchDragEvent, dispatchDraw, dispatchDrawableHotspotChanged, dispatchFinishTemporaryDetach, dispatchFreezeSelfOnly, dispatchGenericFocusedEvent, dispatchGenericPointerEvent, dispatchGetDisplayList, dispatchHoverEvent, dispatchKeyEvent, dispatchKeyEventPreIme, dispatchKeyShortcutEvent, dispatchPopulateAccessibilityEventInternal, dispatchProvideStructure, dispatchSetActivated, dispatchSetPressed, dispatchSetSelected, dispatchStartTemporaryDetach, dispatchSystemUiVisibilityChanged, dispatchThawSelfOnly, dispatchTouchEvent, dispatchTrackballEvent, dispatchUnhandledMove, dispatchVisibilityChanged, dispatchWindowFocusChanged, dispatchWindowSystemUiVisiblityChanged, dispatchWindowVisibilityChanged, drawableStateChanged, encodeProperties, endViewTransition, findFocus, findNamedViews, findViewByAccessibilityIdTraversal, findViewByPredicateTraversal, findViewsWithText, findViewTraversal, findViewWithTagTraversal, focusableViewAvailable, gatherTransparentRegion, getAccessibilityClassName, getChildAt, getChildCount, getChildMeasureSpec, getChildStaticTransformation, getChildVisibleRect, getChildVisibleRect, getClipChildren, getDescendantFocusability, getFocusedChild, getLayoutAnimation, getLayoutAnimationListener, getLayoutMode, getLayoutTransition, getNestedScrollAxes, getOverlay, getPersistentDrawingCache, getTouchscreenBlocksFocus, getTransientView, getTransientViewCount, getTransientViewIndex, hasFocus, hasFocusable, hasHoveredChild, hasTransientState, indexOfChild, internalSetPadding, invalidateChild, invalidateChildInParent, isAlwaysDrawnWithCacheEnabled, isAnimationCacheEnabled, isChildrenDrawingOrderEnabled, isChildrenDrawnWithCacheEnabled, isLayoutSuppressed, isMotionEventSplittingEnabled, isShowingContextMenuWithCoords, isTransformedTouchPointInView, isTransitionGroup, jumpDrawablesToCurrentState, layout, makeOptionalFitsSystemWindows, measureChild, measureChildren, measureChildWithMargins, notifySubtreeAccessibilityStateChanged, offsetChildrenTopAndBottom, offsetDescendantRectToMyCoords, offsetRectIntoDescendantCoords, onChildVisibilityChanged, onCreateDrawableState, onDebugDraw, onDebugDrawMargins, onInitializeAccessibilityNodeInfoInternal, onInterceptHoverEvent, onNestedFling, onNestedPreFling, onNestedPrePerformAccessibilityAction, onNestedPreScroll, onNestedScroll, onNestedScrollAccepted, onRequestSendAccessibilityEvent, onRequestSendAccessibilityEventInternal, onResolvePointerIcon, onSetLayoutParams, onStartNestedScroll, onStopNestedScroll, onViewAdded, onViewRemoved, recomputeViewAttributes, removeAllViews, removeAllViewsInLayout, removeTransientView, removeView, removeViewAt, removeViewInLayout, removeViews, removeViewsInLayout, requestFocus, requestSendAccessibilityEvent, requestTransitionStart, requestTransparentRegion, resetResolvedDrawables, resetResolvedLayoutDirection, resetResolvedPadding, resetResolvedTextAlignment, resetResolvedTextDirection, resolveDrawables, resolveLayoutDirection, resolveLayoutParams, resolvePadding, resolveRtlPropertiesIfNeeded, resolveTextAlignment, resolveTextDirection, scheduleLayoutAnimation, setAddStatesFromChildren, setAlwaysDrawnWithCacheEnabled, setAnimationCacheEnabled, setChildrenDrawingCacheEnabled, setChildrenDrawingOrderEnabled, setChildrenDrawnWithCacheEnabled, setClipChildren, setDescendantFocusability, setLayoutAnimation, setLayoutAnimationListener, setLayoutMode, setLayoutTransition, setMotionEventSplittingEnabled, setOnHierarchyChangeListener, setPersistentDrawingCache, setStaticTransformationsEnabled, setTouchscreenBlocksFocus, setTransitionGroup, shouldDelayChildPressedState, showContextMenuForChild, showContextMenuForChild, startActionModeForChild, startActionModeForChild, startLayoutAnimation, startViewTransition, suppressLayout, transformPointToViewLocal, updateViewLayout
addFocusables, addFrameMetricsListener, addOnAttachStateChangeListener, addOnLayoutChangeListener, animate, announceForAccessibility, applyDrawableToTransparentRegion, awakenScrollBars, awakenScrollBars, awakenScrollBars, bringToFront, buildDrawingCache, buildDrawingCache, buildLayer, callOnClick, cancelDragAndDrop, cancelLongPress, cancelPendingInputEvents, canHaveDisplayList, canResolveLayoutDirection, canResolveTextAlignment, canResolveTextDirection, canScrollHorizontally, canScrollVertically, checkInputConnectionProxy, clearAccessibilityFocus, clearAnimation, combineMeasuredStates, computeFitSystemWindows, computeOpaqueFlags, computeScroll, computeSystemWindowInsets, createAccessibilityNodeInfo, createAccessibilityNodeInfoInternal, createContextMenu, damageInParent, debug, debugIndent, destroyDrawingCache, destroyHardwareResources, dispatchGenericMotionEvent, dispatchNestedPrePerformAccessibilityAction, dispatchPointerEvent, dispatchPopulateAccessibilityEvent, drawableHotspotChanged, encode, findViewById, findViewByPredicate, findViewByPredicateInsideOut, findViewWithTag, fitsSystemWindows, fitSystemWindows, focusSearch, forceHasOverlappingRendering, forceLayout, generateViewId, getAccessibilityDelegate, getAccessibilityLiveRegion, getAccessibilityNodeProvider, getAccessibilitySelectionEnd, getAccessibilitySelectionStart, getAccessibilityTraversalAfter, getAccessibilityTraversalBefore, getAccessibilityViewId, getAccessibilityWindowId, getAlpha, getAnimation, getApplicationWindowToken, getBackground, getBackgroundTintList, getBackgroundTintMode, getBottom, getBottomFadingEdgeStrength, getBottomPaddingOffset, getBoundsOnScreen, getBoundsOnScreen, getCameraDistance, getClipBounds, getClipBounds, getClipToOutline, getContentDescription, getContext, getContextMenuInfo, getDefaultSize, getDisplay, getDrawableState, getDrawingCache, getDrawingCache, getDrawingCacheBackgroundColor, getDrawingCacheQuality, getDrawingRect, getDrawingTime, getElevation, getFadeHeight, getFadeTop, getFilterTouchesWhenObscured, getFitsSystemWindows, getFocusables, getFocusedRect, getForeground, getForegroundGravity, getForegroundTintList, getForegroundTintMode, getGlobalVisibleRect, getGlobalVisibleRect, getHandler, getHardwareRenderer, getHasOverlappingRendering, getHeight, getHitRect, getHorizontalFadingEdgeLength, getHorizontalScrollbarHeight, getHorizontalScrollFactor, getHotspotBounds, getId, getImportantForAccessibility, getInverseMatrix, getIterableTextForAccessibility, getIteratorForGranularity, getKeepScreenOn, getKeyDispatcherState, getLabelFor, getLayerType, getLayoutDirection, getLayoutParams, getLeft, getLeftFadingEdgeStrength, getLeftPaddingOffset, getLocalVisibleRect, getLocationInSurface, getLocationInWindow, getLocationOnScreen, getLocationOnScreen, getMatrix, getMeasuredHeight, getMeasuredHeightAndState, getMeasuredState, getMeasuredWidth, getMeasuredWidthAndState, getMinimumHeight, getMinimumWidth, getNextFocusDownId, getNextFocusForwardId, getNextFocusLeftId, getNextFocusRightId, getNextFocusUpId, getOnFocusChangeListener, getOpticalInsets, getOutlineProvider, getOutsets, getOverScrollMode, getPaddingBottom, getPaddingEnd, getPaddingLeft, getPaddingRight, getPaddingStart, getPaddingTop, getParent, getParentForAccessibility, getPivotX, getPivotY, getPointerIcon, getRawLayoutDirection, getRawTextAlignment, getRawTextDirection, getResources, getRevealOnFocusHint, getRight, getRightFadingEdgeStrength, getRightPaddingOffset, getRootView, getRootWindowInsets, getRotation, getRotationX, getRotationY, getScaleX, getScaleY, getScrollBarDefaultDelayBeforeFade, getScrollBarFadeDuration, getScrollBarSize, getScrollBarStyle, getScrollIndicators, getScrollX, getScrollY, getSolidColor, getStateListAnimator, getSuggestedMinimumHeight, getSuggestedMinimumWidth, getSystemUiVisibility, getTag, getTag, getTextAlignment, getTextDirection, getTop, getTopFadingEdgeStrength, getTopPaddingOffset, getTouchables, getTouchDelegate, getTransitionAlpha, getTransitionName, getTranslationX, getTranslationY, getTranslationZ, getVerticalFadingEdgeLength, getVerticalScrollbarPosition, getVerticalScrollbarWidth, getVerticalScrollFactor, getViewRootImpl, getViewTreeObserver, getVisibility, getWidth, getWindowAttachCount, getWindowDisplayFrame, getWindowId, getWindowSystemUiVisibility, getWindowToken, getWindowVisibility, getWindowVisibleDisplayFrame, getX, getY, getZ, handleScrollBarDragging, hasOnClickListeners, hasOpaqueScrollbars, hasOverlappingRendering, hasShadow, hasWindowFocus, includeForAccessibility, inflate, initializeFadingEdge, initializeFadingEdgeInternal, initializeScrollbars, initializeScrollbarsInternal, invalidate, invalidate, invalidate, invalidateDrawable, invalidateOutline, invalidateParentCaches, invalidateParentIfNeeded, invalidateParentIfNeededAndWasQuickRejected, isAccessibilityFocused, isAccessibilitySelectionExtendable, isActionableForAccessibility, isActivated, isAssistBlocked, isClickable, isContextClickable, isDirty, isDrawingCacheEnabled, isDuplicateParentStateEnabled, isEnabled, isFocusable, isFocusableInTouchMode, isFocused, isForegroundInsidePadding, isHapticFeedbackEnabled, isHardwareAccelerated, isHorizontalFadingEdgeEnabled, isHorizontalScrollBarEnabled, isHovered, isImportantForAccessibility, isInEditMode, isInLayout, isInScrollingContainer, isInTouchMode, isLaidOut, isLayoutDirectionInherited, isLayoutDirectionResolved, isLayoutModeOptical, isLayoutRequested, isLayoutRtl, isLongClickable, isOpaque, isPaddingOffsetRequired, isPaddingRelative, isPressed, isRootNamespace, isSaveEnabled, isSaveFromParentEnabled, isScrollbarFadingEnabled, isScrollContainer, isSelected, isShown, isSoundEffectsEnabled, isTemporarilyDetached, isTextAlignmentInherited, isTextAlignmentResolved, isTextDirectionInherited, isTextDirectionResolved, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, isVerticalScrollBarHidden, isVisibleToUser, isVisibleToUser, measure, mergeDrawableStates, notifySubtreeAccessibilityStateChangedIfNeeded, notifyViewAccessibilityStateChangedIfNeeded, offsetLeftAndRight, offsetTopAndBottom, onActivityResult, onAnimationEnd, onAnimationStart, onApplyWindowInsets, onCancelPendingInputEvents, onCheckIsTextEditor, onCloseSystemDialogs, onConfigurationChanged, onCreateContextMenu, onCreateInputConnection, onDetachedFromWindowInternal, onDisplayHint, onDragEvent, onDrawForeground, onDrawHorizontalScrollBar, onDrawScrollBars, onDrawVerticalScrollBar, onFilterTouchEventForSecurity, onFinishInflate, onFinishTemporaryDetach, onFocusChanged, onFocusLost, onHoverChanged, onHoverEvent, onInitializeAccessibilityEvent, onInitializeAccessibilityEventInternal, onInitializeAccessibilityNodeInfo, onKeyDown, onKeyLongPress, onKeyMultiple, onKeyPreIme, onKeyShortcut, onKeyUp, onOverScrolled, onPopulateAccessibilityEvent, onPopulateAccessibilityEventInternal, onProvideStructure, onProvideVirtualStructure, onRenderNodeDetached, onResolveDrawables, onRtlPropertiesChanged, onScreenStateChanged, onScrollChanged, onSetAlpha, onStartTemporaryDetach, onTrackballEvent, onVisibilityAggregated, onVisibilityChanged, onWindowFocusChanged, onWindowSystemUiVisibilityChanged, onWindowVisibilityChanged, outputDirtyFlags, overScrollBy, performAccessibilityAction, performAccessibilityActionInternal, performButtonActionOnTouchDown, performClick, performContextClick, performContextClick, performHapticFeedback, performHapticFeedback, performLongClick, performLongClick, playSoundEffect, pointInView, post, postDelayed, postInvalidate, postInvalidate, postInvalidateDelayed, postInvalidateDelayed, postInvalidateOnAnimation, postInvalidateOnAnimation, postOnAnimation, postOnAnimationDelayed, recomputePadding, refreshDrawableState, removeCallbacks, removeFrameMetricsListener, removeOnAttachStateChangeListener, removeOnLayoutChangeListener, requestAccessibilityFocus, requestApplyInsets, requestFitSystemWindows, requestFocus, requestFocus, requestFocusFromTouch, requestKeyboardShortcuts, requestRectangleOnScreen, requestRectangleOnScreen, requestUnbufferedDispatch, resetPaddingToInitialValues, resetRtlProperties, resolveSize, resolveSizeAndState, restoreHierarchyState, saveHierarchyState, scheduleDrawable, sendAccessibilityEvent, sendAccessibilityEventInternal, sendAccessibilityEventUncheckedInternal, setAccessibilityDelegate, setAccessibilityLiveRegion, setAccessibilitySelection, setAccessibilityTraversalAfter, setAccessibilityTraversalBefore, setActivated, setAlpha, setAnimation, setAnimationMatrix, setAssistBlocked, setBackground, setBackgroundColor, setBackgroundDrawable, setBackgroundResource, setBackgroundTintList, setBackgroundTintMode, setBottom, setCameraDistance, setClickable, setClipBounds, setClipToOutline, setContentDescription, setContextClickable, setDisabledSystemUiVisibility, setDrawingCacheBackgroundColor, setDrawingCacheEnabled, setDrawingCacheQuality, setDuplicateParentStateEnabled, setElevation, setEnabled, setFadingEdgeLength, setFilterTouchesWhenObscured, setFitsSystemWindows, setFocusable, setFocusableInTouchMode, setForeground, setForegroundGravity, setForegroundTintList, setForegroundTintMode, setFrame, setHapticFeedbackEnabled, setHasTransientState, setHorizontalFadingEdgeEnabled, setHorizontalScrollBarEnabled, setHovered, setId, setImportantForAccessibility, setIsRootNamespace, setKeepScreenOn, setLabelFor, setLayerPaint, setLayerType, setLayoutDirection, setLayoutParams, setLeft, setLeftTopRightBottom, setLongClickable, setMeasuredDimension, setMinimumHeight, setMinimumWidth, setNextFocusDownId, setNextFocusForwardId, setNextFocusLeftId, setNextFocusRightId, setNextFocusUpId, setOnApplyWindowInsetsListener, setOnClickListener, setOnContextClickListener, setOnCreateContextMenuListener, setOnDragListener, setOnFocusChangeListener, setOnGenericMotionListener, setOnHoverListener, setOnKeyListener, setOnLongClickListener, setOnScrollChangeListener, setOnSystemUiVisibilityChangeListener, setOnTouchListener, setOpticalInsets, setOutlineProvider, setOverScrollMode, setPadding, setPaddingRelative, setPivotX, setPivotY, setPointerIcon, setPressed, setRevealClip, setRevealOnFocusHint, setRight, setRotation, setRotationX, setRotationY, setSaveEnabled, setSaveFromParentEnabled, setScaleX, setScaleY, setScrollBarDefaultDelayBeforeFade, setScrollBarFadeDuration, setScrollbarFadingEnabled, setScrollBarSize, setScrollBarStyle, setScrollContainer, setScrollIndicators, setScrollIndicators, setScrollX, setScrollY, setSelected, setSoundEffectsEnabled, setStateListAnimator, setSystemUiVisibility, setTag, setTag, setTagInternal, setTextAlignment, setTextDirection, setTop, setTouchDelegate, setTransitionAlpha, setTransitionName, setTransitionVisibility, setTranslationX, setTranslationY, setTranslationZ, setVerticalFadingEdgeEnabled, setVerticalScrollBarEnabled, setVerticalScrollbarPosition, setVisibility, setWillNotCacheDrawing, setWillNotDraw, setX, setY, setZ, showContextMenu, showContextMenu, startActionMode, startActionMode, startActivityForResult, startAnimation, startDrag, startDragAndDrop, startMovingTask, toGlobalMotionEvent, toLocalMotionEvent, toString, transformFromViewToWindowSpace, transformMatrixToGlobal, transformMatrixToLocal, unscheduleDrawable, unscheduleDrawable, updateDisplayListIfDirty, updateDragShadow, verifyDrawable, willNotCacheDrawing, willNotDraw
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
canResolveLayoutDirection, canResolveTextAlignment, canResolveTextDirection, createContextMenu, getLayoutDirection, getParent, getParentForAccessibility, getTextAlignment, getTextDirection, isLayoutDirectionResolved, isLayoutRequested, isTextAlignmentResolved, isTextDirectionResolved, requestFitSystemWindows
public static final int HORIZONTAL
public static final int VERTICAL
public static final int NO_POSITION
public static final long NO_ID
public static final int INVALID_TYPE
public static final int TOUCH_SLOP_DEFAULT
setScrollingTouchSlop(int)
. Indicates
that the RecyclerView should use the standard touch slop for smooth,
continuous scrolling.public static final int TOUCH_SLOP_PAGING
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.public static final int SCROLL_STATE_IDLE
getScrollState()
,
Constant Field Valuespublic static final int SCROLL_STATE_DRAGGING
getScrollState()
,
Constant Field Valuespublic static final int SCROLL_STATE_SETTLING
getScrollState()
,
Constant Field Valuespublic RecyclerView(Context context)
public RecyclerView(Context context, @Nullable AttributeSet attrs)
public RecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle)
public RecyclerViewAccessibilityDelegate getCompatAccessibilityDelegate()
public void setAccessibilityDelegateCompat(RecyclerViewAccessibilityDelegate accessibilityDelegate)
accessibilityDelegate
- The accessibility delegate to be used by RecyclerView.public void setHasFixedSize(boolean hasFixedSize)
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.
hasFixedSize
- true if adapter changes cannot affect the size of the RecyclerView.public boolean hasFixedSize()
public void setClipToPadding(boolean clipToPadding)
ViewGroup
By default, children are clipped to the padding of their parent ViewGroup. This clipping behavior is only enabled if padding is non-zero.
setClipToPadding
in class ViewGroup
clipToPadding
- true to clip children to the padding of the group, and resize (but
not clip) any EdgeEffect to the padded region. False otherwise.public boolean getClipToPadding()
By default, children are clipped to the padding of their parent RecyclerView. This clipping behavior is only enabled if padding is non-zero.
getClipToPadding
in class ViewGroup
public void setScrollingTouchSlop(int slopConstant)
TOUCH_SLOP_DEFAULT
and TOUCH_SLOP_PAGING
.slopConstant
- One of the TOUCH_SLOP_
constants representing
the intended usage of this RecyclerViewpublic void swapAdapter(RecyclerView.Adapter adapter, boolean removeAndRecycleExistingViews)
setAdapter(Adapter)
but assumes existing adapter and the new adapter uses the same
RecyclerView.ViewHolder
and does not clear the RecycledViewPool.
Note that it still calls onAdapterChanged callbacks.
adapter
- The new adapter to set, or null to set no adapter.removeAndRecycleExistingViews
- 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.setAdapter(Adapter)
public void setAdapter(RecyclerView.Adapter adapter)
When adapter is changed, all existing views are recycled back to the pool. If the pool has only one adapter, it will be cleared.
adapter
- The new adapter to set, or null to set no adapter.swapAdapter(Adapter, boolean)
public RecyclerView.Adapter getAdapter()
setAdapter(Adapter)
public void setRecyclerListener(RecyclerView.RecyclerListener listener)
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.
listener
- Listener to register, or null to clearpublic 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.
getBaseline
in class View
public void addOnChildAttachStateChangeListener(RecyclerView.OnChildAttachStateChangeListener listener)
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.
listener
- Listener to registerpublic void removeOnChildAttachStateChangeListener(RecyclerView.OnChildAttachStateChangeListener listener)
listener
- Listener to unregisterpublic void clearOnChildAttachStateChangeListeners()
addOnChildAttachStateChangeListener(OnChildAttachStateChangeListener)
.public void setLayoutManager(RecyclerView.LayoutManager layout)
RecyclerView.LayoutManager
that this RecyclerView will use.
In contrast to other adapter-backed views such as ListView
or GridView
, RecyclerView allows client code to provide custom
layout arrangements for child views. These arrangements are controlled by the
RecyclerView.LayoutManager
. A LayoutManager must be provided for RecyclerView to function.
Several default strategies are provided for common uses such as lists and grids.
layout
- LayoutManager to usepublic void setOnFlingListener(@Nullable RecyclerView.OnFlingListener onFlingListener)
RecyclerView.OnFlingListener
for this RecyclerView
.
If the RecyclerView.OnFlingListener
is set then it will receive
calls to fling(int,int)
and will be able to intercept them.
onFlingListener
- The RecyclerView.OnFlingListener
instance.@Nullable public RecyclerView.OnFlingListener getOnFlingListener()
RecyclerView.OnFlingListener
from this RecyclerView
.RecyclerView.OnFlingListener
instance currently set (can be null).protected Parcelable onSaveInstanceState()
View
Some examples of things you may store here: the current cursor position in a text view (but usually not the text itself since that is stored in a content provider or other persistent storage), the currently selected item in a list view.
onSaveInstanceState
in class View
View.onRestoreInstanceState(android.os.Parcelable)
,
View.saveHierarchyState(android.util.SparseArray)
,
View.dispatchSaveInstanceState(android.util.SparseArray)
,
View.setSaveEnabled(boolean)
protected void onRestoreInstanceState(Parcelable state)
View
View.onSaveInstanceState()
. This function will never be called with a
null state.onRestoreInstanceState
in class View
state
- The frozen state that had previously been returned by
View.onSaveInstanceState()
.View.onSaveInstanceState()
,
View.restoreHierarchyState(android.util.SparseArray)
,
View.dispatchRestoreInstanceState(android.util.SparseArray)
protected void dispatchSaveInstanceState(SparseArray<Parcelable> container)
dispatchSaveInstanceState
in class ViewGroup
container
- The SparseArray in which to save the view's state.View.dispatchRestoreInstanceState(android.util.SparseArray)
,
View.saveHierarchyState(android.util.SparseArray)
,
View.onSaveInstanceState()
protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container)
dispatchRestoreInstanceState
in class ViewGroup
container
- The SparseArray which holds previously saved state.View.dispatchSaveInstanceState(android.util.SparseArray)
,
View.restoreHierarchyState(android.util.SparseArray)
,
View.onRestoreInstanceState(android.os.Parcelable)
public RecyclerView.LayoutManager getLayoutManager()
RecyclerView.LayoutManager
currently responsible for
layout policy for this RecyclerView.public RecyclerView.RecycledViewPool getRecycledViewPool()
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.setRecycledViewPool(RecycledViewPool)
public void setRecycledViewPool(RecyclerView.RecycledViewPool pool)
ViewPager
.pool
- Pool to set. If this parameter is null a new pool will be created and used.public void setViewCacheExtension(RecyclerView.ViewCacheExtension extension)
RecyclerView.ViewCacheExtension
to be used by the Recycler.extension
- ViewCacheExtension to be used or null if you want to clear the existing one.ViewCacheExtension#getViewForPositionAndType(Recycler, int, int)}
public void setItemViewCacheSize(int size)
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.
size
- Number of views to cache offscreen before returning them to the general
recycled view poolpublic int getScrollState()
SCROLL_STATE_IDLE
, SCROLL_STATE_DRAGGING
or
SCROLL_STATE_SETTLING
public void addItemDecoration(RecyclerView.ItemDecoration decor, int index)
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.
decor
- Decoration to addindex
- Position in the decoration chain to insert this decoration at. If this value
is negative the decoration will be added at the end.public void addItemDecoration(RecyclerView.ItemDecoration decor)
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.
decor
- Decoration to addpublic void removeItemDecoration(RecyclerView.ItemDecoration decor)
RecyclerView.ItemDecoration
from this RecyclerView.
The given decoration will no longer impact the measurement and drawing of item views.
decor
- Decoration to removeaddItemDecoration(ItemDecoration)
public void setChildDrawingOrderCallback(RecyclerView.ChildDrawingOrderCallback childDrawingOrderCallback)
RecyclerView.ChildDrawingOrderCallback
to be used for drawing children.
See ViewGroup.getChildDrawingOrder(int, int)
for details. Calling this method will
always call ViewGroup.setChildrenDrawingOrderEnabled(boolean)
. The parameter will be
true if childDrawingOrderCallback is not null, false otherwise.
Note that child drawing order may be overridden by View's elevation.
childDrawingOrderCallback
- The ChildDrawingOrderCallback to be used by the drawing
system.@Deprecated public void setOnScrollListener(RecyclerView.OnScrollListener listener)
addOnScrollListener(OnScrollListener)
and
removeOnScrollListener(OnScrollListener)
listener
- Listener to set or null to clearpublic void addOnScrollListener(RecyclerView.OnScrollListener listener)
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.
listener
- listener to set or null to clearpublic void removeOnScrollListener(RecyclerView.OnScrollListener listener)
listener
- listener to set or null to clearpublic void clearOnScrollListeners()
public void scrollToPosition(int position)
RecyclerView.LayoutManager.scrollToPosition(int)
position
- Scroll to this adapter positionRecyclerView.LayoutManager.scrollToPosition(int)
public void smoothScrollToPosition(int position)
To support smooth scrolling, you must override
LayoutManager#smoothScrollToPosition(RecyclerView, State, int)
and create a
RecyclerView.SmoothScroller
.
RecyclerView.LayoutManager
is responsible for creating the actual scroll action. If you want to
provide a custom smooth scroll logic, override
LayoutManager#smoothScrollToPosition(RecyclerView, State, int)
in your
LayoutManager.
position
- The adapter position to scroll toLayoutManager#smoothScrollToPosition(RecyclerView, State, int)
public void scrollTo(int x, int y)
View
View.onScrollChanged(int, int, int, int)
and the view will be
invalidated.public void scrollBy(int x, int y)
View
View.onScrollChanged(int, int, int, int)
and the view will be
invalidated.public 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
RecyclerView.LayoutManager.computeHorizontalScrollOffset(RecyclerView.State)
in your
LayoutManager.
computeHorizontalScrollOffset
in interface ScrollingView
computeHorizontalScrollOffset
in class View
(RecyclerView.State)
public 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
RecyclerView.LayoutManager.computeHorizontalScrollExtent(RecyclerView.State)
in your
LayoutManager.
computeHorizontalScrollExtent
in interface ScrollingView
computeHorizontalScrollExtent
in class View
RecyclerView.LayoutManager.computeHorizontalScrollExtent(RecyclerView.State)
public 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
RecyclerView.LayoutManager.computeHorizontalScrollRange(RecyclerView.State)
in your
LayoutManager.
computeHorizontalScrollRange
in interface ScrollingView
computeHorizontalScrollRange
in class View
RecyclerView.LayoutManager.computeHorizontalScrollRange(RecyclerView.State)
public 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
RecyclerView.LayoutManager.computeVerticalScrollOffset(RecyclerView.State)
in your
LayoutManager.
computeVerticalScrollOffset
in interface ScrollingView
computeVerticalScrollOffset
in class View
(RecyclerView.State)
public 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
RecyclerView.LayoutManager.computeVerticalScrollExtent(RecyclerView.State)
in your
LayoutManager.
computeVerticalScrollExtent
in interface ScrollingView
computeVerticalScrollExtent
in class View
RecyclerView.LayoutManager.computeVerticalScrollExtent(RecyclerView.State)
public 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
RecyclerView.LayoutManager.computeVerticalScrollRange(RecyclerView.State)
in your
LayoutManager.
computeVerticalScrollRange
in interface ScrollingView
computeVerticalScrollRange
in class View
RecyclerView.LayoutManager.computeVerticalScrollRange(RecyclerView.State)
public void setLayoutFrozen(boolean frozen)
setLayoutFrozen(true)
is called,
Layout requests will be postponed until setLayoutFrozen(false)
is called;
child views are not updated when RecyclerView is frozen, smoothScrollBy(int, int)
,
scrollBy(int, int)
, scrollToPosition(int)
and
smoothScrollToPosition(int)
are dropped; TouchEvents and GenericMotionEvents are
dropped; LayoutManager#onFocusSearchFailed(View, int, Recycler, State)
will not be
called.
setLayoutFrozen(true)
does not prevent app from directly calling RecyclerView.LayoutManager.scrollToPosition(int)
, LayoutManager#smoothScrollToPosition(
RecyclerView, State, int)
.
setAdapter(Adapter)
and swapAdapter(Adapter, boolean)
will automatically
stop frozen.
Note: Running ItemAnimator is not stopped automatically, it's caller's responsibility to call ItemAnimator.end().
frozen
- true to freeze layout and scroll, false to re-enable.public boolean isLayoutFrozen()
setLayoutFrozen(boolean)
public void smoothScrollBy(int dx, int dy)
dx
- Pixels to scroll horizontallydy
- Pixels to scroll verticallypublic boolean fling(int velocityX, int velocityY)
velocityX
- Initial horizontal velocity in pixels per secondvelocityY
- Initial vertical velocity in pixels per secondRecyclerView.LayoutManager.canScrollVertically()
,
RecyclerView.LayoutManager.canScrollHorizontally()
public void stopScroll()
smoothScrollBy(int, int)
, fling(int, int)
or a touch-initiated fling.public int getMinFlingVelocity()
public int getMaxFlingVelocity()
public View focusSearch(View focused, int direction)
It first does a focus search within the RecyclerView. If this search finds a View that is in
the focus direction with respect to the currently focused View, RecyclerView returns that
child as the next focus target. When it cannot find such child, it calls
LayoutManager#onFocusSearchFailed(View, int, Recycler, State)
to layout more Views
in the focus search direction. If LayoutManager adds a View that matches the
focus search criteria, it will be returned as the focus search result. Otherwise,
RecyclerView will call parent to handle the focus search like a regular ViewGroup.
When the direction is View.FOCUS_FORWARD
or View.FOCUS_BACKWARD
, a View that
is not in the focus direction is still valid focus target which may not be the desired
behavior if the Adapter has more children in the focus direction. To handle this case,
RecyclerView converts the focus direction to an absolute direction and makes a preliminary
focus search in that direction. If there are no Views to gain focus, it will call
LayoutManager#onFocusSearchFailed(View, int, Recycler, State)
before running a
focus search with the original (relative) direction. This allows RecyclerView to provide
better candidates to the focus search while still allowing the view system to take focus from
the RecyclerView and give it to a more suitable child if such child exists.
focusSearch
in interface ViewParent
focusSearch
in class ViewGroup
focused
- The view that currently has focusdirection
- One of View.FOCUS_UP
, View.FOCUS_DOWN
,
View.FOCUS_LEFT
, View.FOCUS_RIGHT
, View.FOCUS_FORWARD
,
View.FOCUS_BACKWARD
or 0 for not applicable.public void requestChildFocus(View child, View focused)
ViewParent
requestChildFocus
in interface ViewParent
requestChildFocus
in class ViewGroup
child
- The child of this ViewParent that wants focus. This view
will contain the focused view. It is not necessarily the view that
actually has focus.focused
- The view that is a descendant of child that actually has
focuspublic boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate)
ViewParent
ViewGroup
s overriding this can trust
that:
ViewGroup
s overriding this should uphold the contract:
requestChildRectangleOnScreen
in interface ViewParent
requestChildRectangleOnScreen
in class ViewGroup
child
- The direct child making the request.rect
- The rectangle in the child's coordinates the child
wishes to be on the screen.immediate
- True to forbid animated or delayed scrolling,
false otherwisepublic void addFocusables(ArrayList<View> views, int direction, int focusableMode)
View
addFocusables
in class ViewGroup
views
- Focusable views found so far or null if all we are interested is
the number of focusables.direction
- The direction of the focus.focusableMode
- The type of focusables to be added.View.FOCUSABLES_ALL
,
View.FOCUSABLES_TOUCH_MODE
protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect)
ViewGroup
View.requestFocus()
on.
Called by ViewGroup.requestFocus(int, android.graphics.Rect)
when it wants to request focus within its children. Override this to
customize how your ViewGroup
requests focus within its children.onRequestFocusInDescendants
in class ViewGroup
direction
- One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHTpreviouslyFocusedRect
- The rectangle (in this View's coordinate system)
to give a finer grained hint about where focus is coming from. May be null
if there is no hint.protected void onAttachedToWindow()
View
View.onDraw(android.graphics.Canvas)
,
however it may be called any time before the first onDraw -- including
before or after View.onMeasure(int, int)
.onAttachedToWindow
in class ViewGroup
View.onDetachedFromWindow()
protected void onDetachedFromWindow()
View
onDetachedFromWindow
in class ViewGroup
View.onAttachedToWindow()
public boolean isAttachedToWindow()
isAttachedToWindow
in class View
public void addOnItemTouchListener(RecyclerView.OnItemTouchListener listener)
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
RecyclerView.OnItemTouchListener.onInterceptTouchEvent(RecyclerView, MotionEvent)
its
RecyclerView.OnItemTouchListener.onTouchEvent(RecyclerView, MotionEvent)
method will be called
for each incoming MotionEvent until the end of the gesture.
listener
- Listener to addRecyclerView.SimpleOnItemTouchListener
public void removeOnItemTouchListener(RecyclerView.OnItemTouchListener listener)
RecyclerView.OnItemTouchListener
. It will no longer be able to intercept touch events.listener
- Listener to removepublic boolean onInterceptTouchEvent(MotionEvent e)
ViewGroup
Using this function takes some care, as it has a fairly complicated
interaction with View.onTouchEvent(MotionEvent)
, and using it requires implementing
that method as well as this one in the correct way. Events will be
received in the following order:
MotionEvent.ACTION_CANCEL
, and all further
events will be delivered to your onTouchEvent() method and no longer
appear here.
onInterceptTouchEvent
in class ViewGroup
e
- The motion event being dispatched down the hierarchy.public void requestDisallowInterceptTouchEvent(boolean disallowIntercept)
ViewParent
ViewGroup.onInterceptTouchEvent(MotionEvent)
.
This parent should pass this call onto its parents. This parent must obey this request for the duration of the touch (that is, only clear the flag after this parent has received an up or a cancel.
requestDisallowInterceptTouchEvent
in interface ViewParent
requestDisallowInterceptTouchEvent
in class ViewGroup
disallowIntercept
- True if the child does not want the parent to
intercept touch events.public boolean onTouchEvent(MotionEvent e)
View
If this method is used to detect click actions, it is recommended that
the actions be performed by implementing and calling
View.performClick()
. This will ensure consistent system behavior,
including:
ACTION_CLICK
when
accessibility features are enabled
onTouchEvent
in class View
e
- The motion event.public boolean onGenericMotionEvent(MotionEvent event)
View
Generic motion events describe joystick movements, mouse hovers, track pad
touches, scroll wheel movements and other input events. The
source
of the motion event specifies
the class of input that was received. Implementations of this method
must examine the bits in the source before processing the event.
The following code example shows how this is done.
Generic motion events with source class InputDevice.SOURCE_CLASS_POINTER
are delivered to the view under the pointer. All other generic motion events are
delivered to the focused view.
public boolean onGenericMotionEvent(MotionEvent event) { if (event.isFromSource(InputDevice.SOURCE_CLASS_JOYSTICK)) { if (event.getAction() == MotionEvent.ACTION_MOVE) { // process the joystick movement... return true; } } if (event.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) { switch (event.getAction()) { case MotionEvent.ACTION_HOVER_MOVE: // process the mouse hover movement... return true; case MotionEvent.ACTION_SCROLL: // process the scroll wheel movement... return true; } } return super.onGenericMotionEvent(event); }
onGenericMotionEvent
in class View
event
- The generic motion event being processed.protected void onMeasure(int widthSpec, int heightSpec)
View
Measure the view and its content to determine the measured width and the
measured height. This method is invoked by View.measure(int, int)
and
should be overridden by subclasses to provide accurate and efficient
measurement of their contents.
CONTRACT: When overriding this method, you
must call View.setMeasuredDimension(int, int)
to store the
measured width and height of this view. Failure to do so will trigger an
IllegalStateException
, thrown by
View.measure(int, int)
. Calling the superclass'
View.onMeasure(int, int)
is a valid use.
The base class implementation of measure defaults to the background size,
unless a larger size is allowed by the MeasureSpec. Subclasses should
override View.onMeasure(int, int)
to provide better measurements of
their content.
If this method is overridden, it is the subclass's responsibility to make
sure the measured height and width are at least the view's minimum height
and width (View.getSuggestedMinimumHeight()
and
View.getSuggestedMinimumWidth()
).
onMeasure
in class View
widthSpec
- horizontal space requirements as imposed by the parent.
The requirements are encoded with
View.MeasureSpec
.heightSpec
- vertical space requirements as imposed by the parent.
The requirements are encoded with
View.MeasureSpec
.View.getMeasuredWidth()
,
View.getMeasuredHeight()
,
View.setMeasuredDimension(int, int)
,
View.getSuggestedMinimumHeight()
,
View.getSuggestedMinimumWidth()
,
View.MeasureSpec.getMode(int)
,
View.MeasureSpec.getSize(int)
protected void onSizeChanged(int w, int h, int oldw, int oldh)
View
onSizeChanged
in class View
w
- Current width of this view.h
- Current height of this view.oldw
- Old width of this view.oldh
- Old height of this view.public void setItemAnimator(RecyclerView.ItemAnimator animator)
RecyclerView.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
.animator
- The ItemAnimator being set. If null, no animations will occur
when changes occur to the items in this RecyclerView.public boolean isComputingLayout()
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.
true
if RecyclerView is currently computing a layout, false
otherwisepublic void sendAccessibilityEventUnchecked(AccessibilityEvent event)
View
View.sendAccessibilityEvent(int)
but
takes as an argument an empty AccessibilityEvent
and does not
perform a check whether accessibility is enabled.
If an View.AccessibilityDelegate
has been specified via calling
View.setAccessibilityDelegate(AccessibilityDelegate)
its
View.AccessibilityDelegate.sendAccessibilityEventUnchecked(View, AccessibilityEvent)
is responsible for handling this call.
sendAccessibilityEventUnchecked
in interface AccessibilityEventSource
sendAccessibilityEventUnchecked
in class View
event
- The event to send.View.sendAccessibilityEvent(int)
public RecyclerView.ItemAnimator getItemAnimator()
DefaultItemAnimator
.protected void removeDetachedView(View child, boolean animate)
ViewGroup
This method is intended to be lightweight and makes no assumptions about whether the
parent or child should be redrawn. Proper use of this method will include also making
any appropriate View.requestLayout()
or View.invalidate()
calls.
For example, callers can post
a Runnable
which performs a View.requestLayout()
on the next frame, after all detach/remove
calls are finished, causing layout to be run prior to redrawing the view hierarchy.
removeDetachedView
in class ViewGroup
child
- the child to be definitely removed from the view hierarchyanimate
- if true and the view has an animation, the view is placed in the
disappearing views list, otherwise, it is detached from the windowViewGroup.attachViewToParent(View, int, android.view.ViewGroup.LayoutParams)
,
ViewGroup.detachAllViewsFromParent()
,
ViewGroup.detachViewFromParent(View)
,
ViewGroup.detachViewFromParent(int)
protected void onLayout(boolean changed, int l, int t, int r, int b)
View
public void requestLayout()
View
View.isInLayout()
. If layout is happening, the request may be honored at the
end of the current layout pass (and then layout will run again) or after the current
frame is drawn and the next layout occurs.
Subclasses which override this method should call the superclass method to handle possible request-during-layout errors correctly.
requestLayout
in interface ViewParent
requestLayout
in class View
public void draw(Canvas c)
View
View.onDraw(android.graphics.Canvas)
instead of overriding this method.
If you do need to override this method, call the superclass version.public void onDraw(Canvas c)
View
protected boolean checkLayoutParams(ViewGroup.LayoutParams p)
checkLayoutParams
in class ViewGroup
protected ViewGroup.LayoutParams generateDefaultLayoutParams()
ViewGroup
ViewGroup.addView(View)
has no layout parameters
already set. If null is returned, an exception is thrown from addView.generateDefaultLayoutParams
in class ViewGroup
public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs)
ViewGroup
generateLayoutParams
in class ViewGroup
attrs
- the attributes to build the layout parameters fromViewGroup.LayoutParams
or one
of its descendantsprotected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p)
ViewGroup
ViewGroup.checkLayoutParams(android.view.ViewGroup.LayoutParams)
, this method
is invoked. This method should return a new set of layout params suitable for
this ViewGroup, possibly by copying the appropriate attributes from the
specified set of layout params.generateLayoutParams
in class ViewGroup
p
- The layout parameters to convert into a suitable set of layout parameters
for this ViewGroup.ViewGroup.LayoutParams
or one
of its descendantspublic boolean isAnimating()
If you want to be notified when animations are finished, use
ItemAnimator#isRunning(ItemAnimator.ItemAnimatorFinishedListener)
.
public void invalidateItemDecorations()
requestLayout()
call.public boolean getPreserveFocusAfterLayout()
By default, this value is true
.
setPreserveFocusAfterLayout(boolean)
public void setPreserveFocusAfterLayout(boolean preserveFocusAfterLayout)
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.
preserveFocusAfterLayout
- Whether RecyclerView should preserve focused Item during a
layout calculations. Defaults to true.getPreserveFocusAfterLayout()
public RecyclerView.ViewHolder getChildViewHolder(View child)
RecyclerView.ViewHolder
for the given child view.child
- Child of this RecyclerView to query for its ViewHolder@Nullable public View findContainingItemView(View view)
getChildViewHolder(View)
.view
- The view that is a descendant of the RecyclerView.getChildViewHolder(View)
,
findContainingViewHolder(View)
@Nullable public RecyclerView.ViewHolder findContainingViewHolder(View view)
view
- The view that is a descendant of the RecyclerView.@Deprecated public int getChildPosition(View child)
getChildAdapterPosition(View)
or
getChildLayoutPosition(View)
.public int getChildAdapterPosition(View child)
child
- Child View to queryNO_POSITION
public int getChildLayoutPosition(View child)
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.
child
- Child View to queryNO_POSITION
if
the View is representing a removed item.public long getChildItemId(View child)
child
- Child View to queryNO_ID
@Deprecated public RecyclerView.ViewHolder findViewHolderForPosition(int position)
findViewHolderForLayoutPosition(int)
or
findViewHolderForAdapterPosition(int)
public RecyclerView.ViewHolder findViewHolderForLayoutPosition(int position)
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
#RecyclerView.ViewHolder.getAdapterPosition()
to get the current adapter position of a ViewHolder.
When the ItemAnimator is running a change animation, there might be 2 ViewHolders with the same layout position representing the same Item. In this case, the updated ViewHolder will be returned.
position
- The position of the item in the data set of the adapterposition
or null if there is no such itempublic RecyclerView.ViewHolder findViewHolderForAdapterPosition(int position)
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
RecyclerView.Adapter.notifyDataSetChanged()
has been called but the new layout has not been
calculated yet, this method will return null
since the new positions of views
are unknown until the layout is calculated.
This method checks only the children of RecyclerView. If the item at the given
position
is not laid out, it will not create a new one.
When the ItemAnimator is running a change animation, there might be 2 ViewHolders representing the same Item. In this case, the updated ViewHolder will be returned.
position
- The position of the item in the data set of the adapterposition
or null if there is no such itempublic RecyclerView.ViewHolder findViewHolderForItemId(long id)
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.
id
- The id for the requested itemid
or null if there is no such itempublic View findChildViewUnder(float x, float y)
x
- Horizontal position in pixels to searchy
- Vertical position in pixels to searchpublic boolean drawChild(Canvas canvas, View child, long drawingTime)
ViewGroup
public void offsetChildrenVertical(int dy)
dy
pixels.
Useful for implementing simple scrolling in LayoutManagers
.dy
- Vertical pixel offset to apply to the bounds of all child viewspublic void onChildAttachedToWindow(View child)
Subclasses of RecyclerView may want to perform extra bookkeeping or modifications
of child views as they become attached. This will be called before a
RecyclerView.LayoutManager
measures or lays out the view and is a good time to perform these
changes.
child
- Child view that is now attached to this RecyclerView and its associated windowpublic void onChildDetachedFromWindow(View child)
Subclasses of RecyclerView may want to perform extra bookkeeping or modifications
of child views as they become detached. This will be called as a
RecyclerView.LayoutManager
fully detaches the child view from the parent and its window.
child
- Child view that is now detached from this RecyclerView and its associated windowpublic void offsetChildrenHorizontal(int dx)
dx
pixels.
Useful for implementing simple scrolling in LayoutManagers
.dx
- Horizontal pixel offset to apply to the bounds of all child viewspublic void getDecoratedBoundsWithMargins(View view, Rect outBounds)
view
- The view element to checkoutBounds
- A rect that will receive the bounds of the element including its
decoration and margins.public void onScrolled(int dx, int dy)
This method will always be invoked before listeners. If a subclass needs to perform any additional upkeep or bookkeeping after scrolling but before listeners run, this is a good place to do so.
This differs from View.onScrollChanged(int, int, int, int)
in that it receives
the distance scrolled in either direction within the adapter's data set instead of absolute
scroll coordinates. Since RecyclerView cannot compute the absolute scroll position from
any arbitrary point in the data set, onScrollChanged
will always receive
the current View.getScrollX()
and View.getScrollY()
values which
do not correspond to the data set scroll position. However, some subclasses may choose
to use these fields as special offsets.
dx
- horizontal distance scrolled in pixelsdy
- vertical distance scrolled in pixelspublic void onScrollStateChanged(int state)
This method will always be invoked before listeners, but after the LayoutManager responds to the scroll state change.
state
- the new scroll state, one of SCROLL_STATE_IDLE
,
SCROLL_STATE_DRAGGING
or SCROLL_STATE_SETTLING
public boolean hasPendingAdapterUpdates()
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.
public void setNestedScrollingEnabled(boolean enabled)
View
If this property is set to true the view will be permitted to initiate nested
scrolling operations with a compatible parent view in the current hierarchy. If this
view does not implement nested scrolling this will have no effect. Disabling nested scrolling
while a nested scroll is in progress has the effect of stopping
the nested scroll.
setNestedScrollingEnabled
in interface NestedScrollingChild
setNestedScrollingEnabled
in class View
enabled
- true to enable nested scrolling, false to disableView.isNestedScrollingEnabled()
public boolean isNestedScrollingEnabled()
View
If nested scrolling is enabled and this View class implementation supports it, this view will act as a nested scrolling child view when applicable, forwarding data about the scroll operation in progress to a compatible and cooperating nested scrolling parent.
isNestedScrollingEnabled
in interface NestedScrollingChild
isNestedScrollingEnabled
in class View
View.setNestedScrollingEnabled(boolean)
public boolean startNestedScroll(int axes)
View
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 this corresponds to the initial MotionEvent.ACTION_DOWN
.
In the case of touch scrolling the nested scroll will be terminated automatically in
the same manner as ViewParent.requestDisallowInterceptTouchEvent(boolean)
.
In the event of programmatic scrolling the caller must explicitly call
View.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 ViewParent.onNestedScroll(View, int, int, int, int)
.
startNestedScroll
in interface NestedScrollingChild
startNestedScroll
in class View
axes
- Flags consisting of a combination of View.SCROLL_AXIS_HORIZONTAL
and/or
View.SCROLL_AXIS_VERTICAL
.View.stopNestedScroll()
,
View.dispatchNestedPreScroll(int, int, int[], int[])
,
View.dispatchNestedScroll(int, int, int, int, int[])
public void stopNestedScroll()
View
Calling this method when a nested scroll is not currently in progress is harmless.
stopNestedScroll
in interface NestedScrollingChild
stopNestedScroll
in class View
View.startNestedScroll(int)
public boolean hasNestedScrollingParent()
View
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.
hasNestedScrollingParent
in interface NestedScrollingChild
hasNestedScrollingParent
in class View
public boolean dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow)
View
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.
dispatchNestedScroll
in interface NestedScrollingChild
dispatchNestedScroll
in class View
dxConsumed
- Horizontal distance in pixels consumed by this view during this scroll stepdyConsumed
- Vertical distance in pixels consumed by this view during this scroll stepdxUnconsumed
- Horizontal scroll distance in pixels not consumed by this viewdyUnconsumed
- Horizontal scroll distance in pixels not consumed by this viewoffsetInWindow
- 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.View.dispatchNestedPreScroll(int, int, int[], int[])
public boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow)
View
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.
dispatchNestedPreScroll
in interface NestedScrollingChild
dispatchNestedPreScroll
in class View
dx
- Horizontal scroll distance in pixelsdy
- Vertical scroll distance in pixelsconsumed
- Output. If not null, consumed[0] will contain the consumed component of dx
and consumed[1] the consumed dy.offsetInWindow
- 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.View.dispatchNestedScroll(int, int, int, int, int[])
public boolean dispatchNestedFling(float velocityX, float velocityY, boolean consumed)
View
This method should be used to indicate that a nested scrolling child has detected
suitable conditions for a fling. Generally this means that a touch scroll has ended with a
velocity
in the direction of scrolling that meets or exceeds
the minimum fling velocity
along a scrollable axis.
If a nested scrolling child view would normally fling but it is at the edge of its own content, it can use this method to delegate the fling to its nested scrolling parent instead. The parent may optionally consume the fling or observe a child fling.
dispatchNestedFling
in interface NestedScrollingChild
dispatchNestedFling
in class View
velocityX
- Horizontal fling velocity in pixels per secondvelocityY
- Vertical fling velocity in pixels per secondconsumed
- true if the child consumed the fling, false otherwisepublic boolean dispatchNestedPreFling(float velocityX, float velocityY)
View
Nested pre-fling events are to nested fling events what touch intercept is to touch
and what nested pre-scroll is to nested scroll. dispatchNestedPreFling
offsets an opportunity for the parent view in a nested fling to fully consume the fling
before the child view consumes it. If this method returns true
, a nested
parent view consumed the fling and this view should not scroll as a result.
For a better user experience, only one view in a nested scrolling chain should consume the fling at a time. If a parent view consumed the fling this method will return false. Custom view implementations should account for this in two ways:
dispatchNestedPreFling
; consume the fling and settle to a valid
position regardless.Views should also not offer fling velocities to nested parent views along an axis
where scrolling is not currently supported; a ScrollView
should not offer a horizontal fling velocity to its parents since scrolling along that
axis is not permitted and carrying velocity along that motion does not make sense.
dispatchNestedPreFling
in interface NestedScrollingChild
dispatchNestedPreFling
in class View
velocityX
- Horizontal fling velocity in pixels per secondvelocityY
- Vertical fling velocity in pixels per secondprotected int getChildDrawingOrder(int childCount, int i)
ViewGroup
NOTE: In order for this method to be called, you must enable child ordering
first by calling ViewGroup.setChildrenDrawingOrderEnabled(boolean)
.
getChildDrawingOrder
in class ViewGroup
i
- The current iteration.ViewGroup.setChildrenDrawingOrderEnabled(boolean)
,
ViewGroup.isChildrenDrawingOrderEnabled()