android官方API之RecyclerView

来源:https://developer.android.com/reference/android/support/v7/widget/RecyclerView

RecyclerView

public class RecyclerView 
extends ViewGroup implements ScrollingViewNestedScrollingChild2

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.support.v7.widget.RecyclerView
Known Direct Subclasses

BaseGridView,WearableRecyclerView

Known Indirect Subclasses

HorizontalGridView,VerticalGridView


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 andRecyclerView.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 RecyclerView

class RecyclerView.AdapterDataObserver

Observer base class for watching changes to an RecyclerView.Adapter

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

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. 

class RecyclerView.LayoutParams

LayoutParams subclass for children of RecyclerView

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 RecyclerView.OnItemTouchListener that has empty method bodies and default return values. 

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 setScrollingTouchSlop(int).

int TOUCH_SLOP_PAGING

Constant for use with setScrollingTouchSlop(int).

int VERTICAL

Inherited constants

From class android.view.ViewGroup
int CLIP_TO_PADDING_MASK
int FOCUS_AFTER_DESCENDANTS
int FOCUS_BEFORE_DESCENDANTS
int FOCUS_BLOCK_DESCENDANTS
int LAYOUT_MODE_CLIP_BOUNDS
int LAYOUT_MODE_OPTICAL_BOUNDS
int PERSISTENT_ALL_CACHES
int PERSISTENT_ANIMATION_CACHE
int PERSISTENT_NO_CACHE
int PERSISTENT_SCROLLING_CACHE
From class android.view.View
int ACCESSIBILITY_LIVE_REGION_ASSERTIVE
int ACCESSIBILITY_LIVE_REGION_NONE
int ACCESSIBILITY_LIVE_REGION_POLITE
int AUTOFILL_FLAG_INCLUDE_NOT_IMPORTANT_VIEWS
String AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE
String AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY
String AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH
String AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR
String AUTOFILL_HINT_CREDIT_CARD_NUMBER
String AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE
String AUTOFILL_HINT_EMAIL_ADDRESS
String AUTOFILL_HINT_NAME
String AUTOFILL_HINT_PASSWORD
String AUTOFILL_HINT_PHONE
String AUTOFILL_HINT_POSTAL_ADDRESS
String AUTOFILL_HINT_POSTAL_CODE
String AUTOFILL_HINT_USERNAME
int AUTOFILL_TYPE_DATE
int AUTOFILL_TYPE_LIST
int AUTOFILL_TYPE_NONE
int AUTOFILL_TYPE_TEXT
int AUTOFILL_TYPE_TOGGLE
int DRAG_FLAG_GLOBAL
int DRAG_FLAG_GLOBAL_PERSISTABLE_URI_PERMISSION
int DRAG_FLAG_GLOBAL_PREFIX_URI_PERMISSION
int DRAG_FLAG_GLOBAL_URI_READ
int DRAG_FLAG_GLOBAL_URI_WRITE
int DRAG_FLAG_OPAQUE
int DRAWING_CACHE_QUALITY_AUTO
int DRAWING_CACHE_QUALITY_HIGH
int DRAWING_CACHE_QUALITY_LOW
int FIND_VIEWS_WITH_CONTENT_DESCRIPTION
int FIND_VIEWS_WITH_TEXT
int FOCUSABLE
int FOCUSABLES_ALL
int FOCUSABLES_TOUCH_MODE
int FOCUSABLE_AUTO
int FOCUS_BACKWARD
int FOCUS_DOWN
int FOCUS_FORWARD
int FOCUS_LEFT
int FOCUS_RIGHT
int FOCUS_UP
int GONE
int HAPTIC_FEEDBACK_ENABLED
int IMPORTANT_FOR_ACCESSIBILITY_AUTO
int IMPORTANT_FOR_ACCESSIBILITY_NO
int IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
int IMPORTANT_FOR_ACCESSIBILITY_YES
int IMPORTANT_FOR_AUTOFILL_AUTO
int IMPORTANT_FOR_AUTOFILL_NO
int IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS
int IMPORTANT_FOR_AUTOFILL_YES
int IMPORTANT_FOR_AUTOFILL_YES_EXCLUDE_DESCENDANTS
int INVISIBLE
int KEEP_SCREEN_ON
int LAYER_TYPE_HARDWARE
int LAYER_TYPE_NONE
int LAYER_TYPE_SOFTWARE
int LAYOUT_DIRECTION_INHERIT
int LAYOUT_DIRECTION_LOCALE
int LAYOUT_DIRECTION_LTR
int LAYOUT_DIRECTION_RTL
int MEASURED_HEIGHT_STATE_SHIFT
int MEASURED_SIZE_MASK
int MEASURED_STATE_MASK
int MEASURED_STATE_TOO_SMALL
int NOT_FOCUSABLE
int NO_ID
int OVER_SCROLL_ALWAYS
int OVER_SCROLL_IF_CONTENT_SCROLLS
int OVER_SCROLL_NEVER
int SCREEN_STATE_OFF
int SCREEN_STATE_ON
int SCROLLBARS_INSIDE_INSET
int SCROLLBARS_INSIDE_OVERLAY
int SCROLLBARS_OUTSIDE_INSET
int SCROLLBARS_OUTSIDE_OVERLAY
int SCROLLBAR_POSITION_DEFAULT
int SCROLLBAR_POSITION_LEFT
int SCROLLBAR_POSITION_RIGHT
int SCROLL_AXIS_HORIZONTAL
int SCROLL_AXIS_NONE
int SCROLL_AXIS_VERTICAL
int SCROLL_INDICATOR_BOTTOM
int SCROLL_INDICATOR_END
int SCROLL_INDICATOR_LEFT
int SCROLL_INDICATOR_RIGHT
int SCROLL_INDICATOR_START
int SCROLL_INDICATOR_TOP
int SOUND_EFFECTS_ENABLED
int STATUS_BAR_HIDDEN
int STATUS_BAR_VISIBLE
int SYSTEM_UI_FLAG_FULLSCREEN
int SYSTEM_UI_FLAG_HIDE_NAVIGATION
int SYSTEM_UI_FLAG_IMMERSIVE
int SYSTEM_UI_FLAG_IMMERSIVE_STICKY
int SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
int SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
int SYSTEM_UI_FLAG_LAYOUT_STABLE
int SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
int SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
int SYSTEM_UI_FLAG_LOW_PROFILE
int SYSTEM_UI_FLAG_VISIBLE
int SYSTEM_UI_LAYOUT_FLAGS
int TEXT_ALIGNMENT_CENTER
int TEXT_ALIGNMENT_GRAVITY
int TEXT_ALIGNMENT_INHERIT
int TEXT_ALIGNMENT_TEXT_END
int TEXT_ALIGNMENT_TEXT_START
int TEXT_ALIGNMENT_VIEW_END
int TEXT_ALIGNMENT_VIEW_START
int TEXT_DIRECTION_ANY_RTL
int TEXT_DIRECTION_FIRST_STRONG
int TEXT_DIRECTION_FIRST_STRONG_LTR
int TEXT_DIRECTION_FIRST_STRONG_RTL
int TEXT_DIRECTION_INHERIT
int TEXT_DIRECTION_LOCALE
int TEXT_DIRECTION_LTR
int TEXT_DIRECTION_RTL
String VIEW_LOG_TAG
int VISIBLE

Inherited fields

From class android.view.View
public static final Property<View, Float> ALPHA
protected static final int[] EMPTY_STATE_SET
protected static final int[] ENABLED_FOCUSED_SELECTED_STATE_SET
protected static final int[] ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET
protected static final int[] ENABLED_FOCUSED_STATE_SET
protected static final int[] ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET
protected static final int[] ENABLED_SELECTED_STATE_SET
protected static final int[] ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET
protected static final int[] ENABLED_STATE_SET
protected static final int[] ENABLED_WINDOW_FOCUSED_STATE_SET
protected static final int[] FOCUSED_SELECTED_STATE_SET
protected static final int[] FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET
protected static final int[] FOCUSED_STATE_SET
protected static final int[] FOCUSED_WINDOW_FOCUSED_STATE_SET
protected static final int[] PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET
protected static final int[] PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET
protected static final int[] PRESSED_ENABLED_FOCUSED_STATE_SET
protected static final int[] PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET
protected static final int[] PRESSED_ENABLED_SELECTED_STATE_SET
protected static final int[] PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET
protected static final int[] PRESSED_ENABLED_STATE_SET
protected static final int[] PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET
protected static final int[] PRESSED_FOCUSED_SELECTED_STATE_SET
protected static final int[] PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET
protected static final int[] PRESSED_FOCUSED_STATE_SET
protected static final int[] PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET
protected static final int[] PRESSED_SELECTED_STATE_SET
protected static final int[] PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET
protected static final int[] PRESSED_STATE_SET
protected static final int[] PRESSED_WINDOW_FOCUSED_STATE_SET
public static final Property<View, Float> ROTATION
public static final Property<View, Float> ROTATION_X
public static final Property<View, Float> ROTATION_Y
public static final Property<View, Float> SCALE_X
public static final Property<View, Float> SCALE_Y
protected static final int[] SELECTED_STATE_SET
protected static final int[] SELECTED_WINDOW_FOCUSED_STATE_SET
public static final Property<View, Float> TRANSLATION_X
public static final Property<View, Float> TRANSLATION_Y
public static final Property<View, Float> TRANSLATION_Z
protected static final int[] WINDOW_FOCUSED_STATE_SET
public static final Property<View, Float> X
public static final Property<View, Float> Y
public static final Property<View, Float> Z

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

void clearOnChildAttachStateChangeListeners()

Removes all listeners that were added viaaddOnChildAttachStateChangeListener(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)
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 findViewHolderForLayoutPosition(int)or findViewHolderForAdapterPosition(int)

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 getChildAdapterPosition(View) orgetChildLayoutPosition(View).

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.EdgeEffectFactory getEdgeEffectFactory()

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

RecyclerView.ItemAnimator getItemAnimator()

Gets the current ItemAnimator for this RecyclerView.

RecyclerView.ItemDecoration getItemDecorationAt(int index)

Returns an RecyclerView.ItemDecoration previously added to this RecyclerView.

int getItemDecorationCount()

Returns the number of RecyclerView.ItemDecoration currently added to 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()
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 dx pixels.

void offsetChildrenVertical(int dy)

Offset the bounds of all child views by dy pixels.

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 RecyclerView.ItemDecoration from this RecyclerView.

void removeItemDecorationAt(int index)

Removes the RecyclerView.ItemDecoration associated with the supplied index position.

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)
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(RecyclerViewAccessibilityDelegateaccessibilityDelegate)

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.ChildDrawingOrderCallbackchildDrawingOrderCallback)

Sets the RecyclerView.ChildDrawingOrderCallback to be used for drawing children.

void setClipToPadding(boolean clipToPadding)
void setEdgeEffectFactory(RecyclerView.EdgeEffectFactory edgeEffectFactory)

Set a RecyclerView.EdgeEffectFactory for this RecyclerView.

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)
void setOnFlingListener(RecyclerView.OnFlingListener onFlingListener)

Set a RecyclerView.OnFlingListener for this RecyclerView.

void setOnScrollListener(RecyclerView.OnScrollListener listener)

This method was deprecated in API level 22.1.0. Use addOnScrollListener(OnScrollListener) andremoveOnScrollListener(OnScrollListener)

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 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 smoothScrollBy(int, int)fling(int, int) or a touch-initiated fling.

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

From class android.view.ViewGroup
void addChildrenForAccessibility(ArrayList<View> arg0)
void addFocusables(ArrayList<View> arg0, int arg1, int arg2)
void addKeyboardNavigationClusters(Collection<View> arg0, int arg1)
boolean addStatesFromChildren()
void addTouchables(ArrayList<View> arg0)
void addView(View arg0, ViewGroup.LayoutParams arg1)
void addView(View arg0, int arg1)
void addView(View arg0, int arg1, ViewGroup.LayoutParams arg2)
void addView(View arg0)
void addView(View arg0, int arg1, int arg2)
boolean addViewInLayout(View arg0, int arg1, ViewGroup.LayoutParams arg2,boolean arg3)
boolean addViewInLayout(View arg0, int arg1, ViewGroup.LayoutParams arg2)
void attachLayoutAnimationParameters(View arg0, ViewGroup.LayoutParamsarg1, int arg2, int arg3)
void attachViewToParent(View arg0, int arg1, ViewGroup.LayoutParams arg2)
void bringChildToFront(View arg0)
boolean canAnimate()
boolean checkLayoutParams(ViewGroup.LayoutParams arg0)
void childDrawableStateChanged(View arg0)
void childHasTransientStateChanged(View arg0, boolean arg1)
void cleanupLayoutState(View arg0)
void clearChildFocus(View arg0)
void clearDisappearingChildren()
void clearFocus()
void debug(int arg0)
void detachAllViewsFromParent()
void detachViewFromParent(int arg0)
void detachViewFromParent(View arg0)
void detachViewsFromParent(int arg0, int arg1)
WindowInsets dispatchApplyWindowInsets(WindowInsets arg0)
boolean dispatchCapturedPointerEvent(MotionEvent arg0)
void dispatchConfigurationChanged(Configuration arg0)
void dispatchDisplayHint(int arg0)
boolean dispatchDragEvent(DragEvent arg0)
void dispatchDraw(Canvas arg0)
void dispatchDrawableHotspotChanged(float arg0, float arg1)
void dispatchFreezeSelfOnly(SparseArray<Parcelable> arg0)
boolean dispatchGenericFocusedEvent(MotionEvent arg0)
boolean dispatchGenericPointerEvent(MotionEvent arg0)
boolean dispatchHoverEvent(MotionEvent arg0)
boolean dispatchKeyEvent(KeyEvent arg0)
boolean dispatchKeyEventPreIme(KeyEvent arg0)
boolean dispatchKeyShortcutEvent(KeyEvent arg0)
void dispatchPointerCaptureChanged(boolean arg0)
void dispatchProvideAutofillStructure(ViewStructure arg0, int arg1)
void dispatchProvideStructure(ViewStructure arg0)
void dispatchRestoreInstanceState(SparseArray<Parcelable> arg0)
void dispatchSaveInstanceState(SparseArray<Parcelable> arg0)
void dispatchSetActivated(boolean arg0)
void dispatchSetPressed(boolean arg0)
void dispatchSetSelected(boolean arg0)
void dispatchSystemUiVisibilityChanged(int arg0)
void dispatchThawSelfOnly(SparseArray<Parcelable> arg0)
boolean dispatchTouchEvent(MotionEvent arg0)
boolean dispatchTrackballEvent(MotionEvent arg0)
boolean dispatchUnhandledMove(View arg0, int arg1)
void dispatchVisibilityChanged(View arg0, int arg1)
void dispatchWindowFocusChanged(boolean arg0)
void dispatchWindowSystemUiVisiblityChanged(int arg0)
void dispatchWindowVisibilityChanged(int arg0)
boolean drawChild(Canvas arg0, View arg1, long arg2)
void drawableStateChanged()
void endViewTransition(View arg0)
View findFocus()
void findViewsWithText(ArrayList<View> arg0, CharSequence arg1, int arg2)
View focusSearch(View arg0, int arg1)
void focusableViewAvailable(View arg0)
boolean gatherTransparentRegion(Region arg0)
ViewGroup.LayoutParams generateDefaultLayoutParams()
ViewGroup.LayoutParams generateLayoutParams(AttributeSet arg0)
ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams arg0)
CharSequence getAccessibilityClassName()
View getChildAt(int arg0)
int getChildCount()
int getChildDrawingOrder(int arg0, int arg1)
static int getChildMeasureSpec(int arg0, int arg1, int arg2)
boolean getChildStaticTransformation(View arg0, Transformation arg1)
boolean getChildVisibleRect(View arg0, Rect arg1, Point arg2)
boolean getClipChildren()
boolean getClipToPadding()
int getDescendantFocusability()
View getFocusedChild()
LayoutAnimationController getLayoutAnimation()
Animation.AnimationListener getLayoutAnimationListener()
int getLayoutMode()
LayoutTransition getLayoutTransition()
int getNestedScrollAxes()
ViewOverlay getOverlay()
int getPersistentDrawingCache()
boolean getTouchscreenBlocksFocus()
boolean hasFocus()
boolean hasTransientState()
int indexOfChild(View arg0)
final void invalidateChild(View arg0, Rect arg1)
ViewParent invalidateChildInParent(int[] arg0, Rect arg1)
boolean isAlwaysDrawnWithCacheEnabled()
boolean isAnimationCacheEnabled()
boolean isChildrenDrawingOrderEnabled()
boolean isChildrenDrawnWithCacheEnabled()
boolean isMotionEventSplittingEnabled()
boolean isTransitionGroup()
void jumpDrawablesToCurrentState()
final void layout(int arg0, int arg1, int arg2, int arg3)
void measureChild(View arg0, int arg1, int arg2)
void measureChildWithMargins(View arg0, int arg1, int arg2, int arg3, int arg4)
void measureChildren(int arg0, int arg1)
void notifySubtreeAccessibilityStateChanged(View arg0, View arg1, int arg2)
final void offsetDescendantRectToMyCoords(View arg0, Rect arg1)
final void offsetRectIntoDescendantCoords(View arg0, Rect arg1)
void onAttachedToWindow()
int[] onCreateDrawableState(int arg0)
void onDescendantInvalidated(View arg0, View arg1)
void onDetachedFromWindow()
boolean onInterceptHoverEvent(MotionEvent arg0)
boolean onInterceptTouchEvent(MotionEvent arg0)
abstract void onLayout(boolean arg0, int arg1, int arg2, int arg3, int arg4)
boolean onNestedFling(View arg0, float arg1, float arg2, boolean arg3)
boolean onNestedPreFling(View arg0, float arg1, float arg2)
boolean onNestedPrePerformAccessibilityAction(View arg0, int arg1, Bundlearg2)
void onNestedPreScroll(View arg0, int arg1, int arg2, int[] arg3)
void onNestedScroll(View arg0, int arg1, int arg2, int arg3, int arg4)
void onNestedScrollAccepted(View arg0, View arg1, int arg2)
boolean onRequestFocusInDescendants(int arg0, Rect arg1)
boolean onRequestSendAccessibilityEvent(View arg0, AccessibilityEvent arg1)
PointerIcon onResolvePointerIcon(MotionEvent arg0, int arg1)
boolean onStartNestedScroll(View arg0, View arg1, int arg2)
void onStopNestedScroll(View arg0)
void onViewAdded(View arg0)
void onViewRemoved(View arg0)
void recomputeViewAttributes(View arg0)
void removeAllViews()
void removeAllViewsInLayout()
void removeDetachedView(View arg0, boolean arg1)
void removeView(View arg0)
void removeViewAt(int arg0)
void removeViewInLayout(View arg0)
void removeViews(int arg0, int arg1)
void removeViewsInLayout(int arg0, int arg1)
void requestChildFocus(View arg0, View arg1)
boolean requestChildRectangleOnScreen(View arg0, Rect arg1, boolean arg2)
void requestDisallowInterceptTouchEvent(boolean arg0)
boolean requestFocus(int arg0, Rect arg1)
boolean requestSendAccessibilityEvent(View arg0, AccessibilityEvent arg1)
void requestTransparentRegion(View arg0)
boolean restoreDefaultFocus()
void scheduleLayoutAnimation()
void setAddStatesFromChildren(boolean arg0)
void setAlwaysDrawnWithCacheEnabled(boolean arg0)
void setAnimationCacheEnabled(boolean arg0)
void setChildrenDrawingCacheEnabled(boolean arg0)
void setChildrenDrawingOrderEnabled(boolean arg0)
void setChildrenDrawnWithCacheEnabled(boolean arg0)
void setClipChildren(boolean arg0)
void setClipToPadding(boolean arg0)
void setDescendantFocusability(int arg0)
void setLayoutAnimation(LayoutAnimationController arg0)
void setLayoutAnimationListener(Animation.AnimationListener arg0)
void setLayoutMode(int arg0)
void setLayoutTransition(LayoutTransition arg0)
void setMotionEventSplittingEnabled(boolean arg0)
void setOnHierarchyChangeListener(ViewGroup.OnHierarchyChangeListener arg0)
void setPersistentDrawingCache(int arg0)
void setStaticTransformationsEnabled(boolean arg0)
void setTouchscreenBlocksFocus(boolean arg0)
void setTransitionGroup(boolean arg0)
boolean shouldDelayChildPressedState()
boolean showContextMenuForChild(View arg0, float arg1, float arg2)
boolean showContextMenuForChild(View arg0)
ActionMode startActionModeForChild(View arg0, ActionMode.Callback arg1, int arg2)
ActionMode startActionModeForChild(View arg0, ActionMode.Callback arg1)
void startLayoutAnimation()
void startViewTransition(View arg0)
void updateViewLayout(View arg0, ViewGroup.LayoutParams arg1)
From class android.view.View
void addChildrenForAccessibility(ArrayList<View> arg0)
void addExtraDataToAccessibilityNodeInfo(AccessibilityNodeInfo arg0, String arg1, Bundle arg2)
void addFocusables(ArrayList<View> arg0, int arg1)
void addFocusables(ArrayList<View> arg0, int arg1, int arg2)
void addKeyFallbackListener(View.OnKeyFallbackListener arg0)
void addKeyboardNavigationClusters(Collection<View> arg0, int arg1)
void addOnAttachStateChangeListener(View.OnAttachStateChangeListener arg0)
void addOnLayoutChangeListener(View.OnLayoutChangeListener arg0)
void addTouchables(ArrayList<View> arg0)
ViewPropertyAnimator animate()
void announceForAccessibility(CharSequence arg0)
void autofill(AutofillValue arg0)
void autofill(SparseArray<AutofillValue> arg0)
boolean awakenScrollBars(int arg0, boolean arg1)
boolean awakenScrollBars(int arg0)
boolean awakenScrollBars()
void bringToFront()
void buildDrawingCache(boolean arg0)
void buildDrawingCache()
void buildLayer()
boolean callOnClick()
boolean canResolveLayoutDirection()
boolean canResolveTextAlignment()
boolean canResolveTextDirection()
boolean canScrollHorizontally(int arg0)
boolean canScrollVertically(int arg0)
final void cancelDragAndDrop()
void cancelLongPress()
final void cancelPendingInputEvents()
boolean checkInputConnectionProxy(View arg0)
void clearAnimation()
void clearFocus()
static int combineMeasuredStates(int arg0, int arg1)
int computeHorizontalScrollExtent()
int computeHorizontalScrollOffset()
int computeHorizontalScrollRange()
void computeScroll()
WindowInsets computeSystemWindowInsets(WindowInsets arg0, Rect arg1)
int computeVerticalScrollExtent()
int computeVerticalScrollOffset()
int computeVerticalScrollRange()
AccessibilityNodeInfo createAccessibilityNodeInfo()
void createContextMenu(ContextMenu arg0)
void destroyDrawingCache()
WindowInsets dispatchApplyWindowInsets(WindowInsets arg0)
boolean dispatchCapturedPointerEvent(MotionEvent arg0)
void dispatchConfigurationChanged(Configuration arg0)
void dispatchDisplayHint(int arg0)
boolean dispatchDragEvent(DragEvent arg0)
void dispatchDraw(Canvas arg0)
void dispatchDrawableHotspotChanged(float arg0, float arg1)
void dispatchFinishTemporaryDetach()
boolean dispatchGenericFocusedEvent(MotionEvent arg0)
boolean dispatchGenericMotionEvent(MotionEvent arg0)
boolean dispatchGenericPointerEvent(MotionEvent arg0)
boolean dispatchHoverEvent(MotionEvent arg0)
boolean dispatchKeyEvent(KeyEvent arg0)
boolean dispatchKeyEventPreIme(KeyEvent arg0)
boolean dispatchKeyShortcutEvent(KeyEvent arg0)
boolean dispatchNestedFling(float arg0, float arg1, boolean arg2)
boolean dispatchNestedPreFling(float arg0, float arg1)
boolean dispatchNestedPrePerformAccessibilityAction(int arg0, Bundle arg1)
boolean dispatchNestedPreScroll(int arg0, int arg1, int[] arg2, int[] arg3)
boolean dispatchNestedScroll(int arg0, int arg1, int arg2, int arg3, int[] arg4)
void dispatchPointerCaptureChanged(boolean arg0)
boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent arg0)
void dispatchProvideAutofillStructure(ViewStructure arg0, int arg1)
void dispatchProvideStructure(ViewStructure arg0)
void dispatchRestoreInstanceState(SparseArray<Parcelable> arg0)
void dispatchSaveInstanceState(SparseArray<Parcelable> arg0)
void dispatchSetActivated(boolean arg0)
void dispatchSetPressed(boolean arg0)
void dispatchSetSelected(boolean arg0)
void dispatchStartTemporaryDetach()
void dispatchSystemUiVisibilityChanged(int arg0)
boolean dispatchTouchEvent(MotionEvent arg0)
boolean dispatchTrackballEvent(MotionEvent arg0)
boolean dispatchUnhandledMove(View arg0, int arg1)
void dispatchVisibilityChanged(View arg0, int arg1)
void dispatchWindowFocusChanged(boolean arg0)
void dispatchWindowSystemUiVisiblityChanged(int arg0)
void dispatchWindowVisibilityChanged(int arg0)
void draw(Canvas arg0)
void drawableHotspotChanged(float arg0, float arg1)
void drawableStateChanged()
View findFocus()
final <T extends View> T findViewById(int arg0)
final <T extends View> T findViewWithTag(Object arg0)
void findViewsWithText(ArrayList<View> arg0, CharSequence arg1, int arg2)
boolean fitSystemWindows(Rect arg0)
View focusSearch(int arg0)
void forceHasOverlappingRendering(boolean arg0)
void forceLayout()
static int generateViewId()
CharSequence getAccessibilityClassName()
int getAccessibilityLiveRegion()
AccessibilityNodeProvider getAccessibilityNodeProvider()
CharSequence getAccessibilityPaneTitle()
int getAccessibilityTraversalAfter()
int getAccessibilityTraversalBefore()
float getAlpha()
Animation getAnimation()
IBinder getApplicationWindowToken()
String[] getAutofillHints()
final AutofillId getAutofillId()
int getAutofillType()
AutofillValue getAutofillValue()
Drawable getBackground()
ColorStateList getBackgroundTintList()
PorterDuff.Mode getBackgroundTintMode()
int getBaseline()
final int getBottom()
float getBottomFadingEdgeStrength()
int getBottomPaddingOffset()
float getCameraDistance()
boolean getClipBounds(Rect arg0)
Rect getClipBounds()
final boolean getClipToOutline()
CharSequence getContentDescription()
final Context getContext()
ContextMenu.ContextMenuInfo getContextMenuInfo()
final boolean getDefaultFocusHighlightEnabled()
static int getDefaultSize(int arg0, int arg1)
Display getDisplay()
final int[] getDrawableState()
Bitmap getDrawingCache()
Bitmap getDrawingCache(boolean arg0)
int getDrawingCacheBackgroundColor()
int getDrawingCacheQuality()
void getDrawingRect(Rect arg0)
long getDrawingTime()
float getElevation()
boolean getFilterTouchesWhenObscured()
boolean getFitsSystemWindows()
int getFocusable()
ArrayList<View> getFocusables(int arg0)
void getFocusedRect(Rect arg0)
Drawable getForeground()
int getForegroundGravity()
ColorStateList getForegroundTintList()
PorterDuff.Mode getForegroundTintMode()
final boolean getGlobalVisibleRect(Rect arg0)
boolean getGlobalVisibleRect(Rect arg0, Point arg1)
Handler getHandler()
final boolean getHasOverlappingRendering()
final int getHeight()
void getHitRect(Rect arg0)
int getHorizontalFadingEdgeLength()
int getHorizontalScrollbarHeight()
int getId()
int getImportantForAccessibility()
int getImportantForAutofill()
boolean getKeepScreenOn()
KeyEvent.DispatcherState getKeyDispatcherState()
int getLabelFor()
int getLayerType()
int getLayoutDirection()
ViewGroup.LayoutParams getLayoutParams()
final int getLeft()
float getLeftFadingEdgeStrength()
int getLeftPaddingOffset()
final boolean getLocalVisibleRect(Rect arg0)
void getLocationInWindow(int[] arg0)
void getLocationOnScreen(int[] arg0)
Matrix getMatrix()
final int getMeasuredHeight()
final int getMeasuredHeightAndState()
final int getMeasuredState()
final int getMeasuredWidth()
final int getMeasuredWidthAndState()
int getMinimumHeight()
int getMinimumWidth()
int getNextClusterForwardId()
int getNextFocusDownId()
int getNextFocusForwardId()
int getNextFocusLeftId()
int getNextFocusRightId()
int getNextFocusUpId()
View.OnFocusChangeListener getOnFocusChangeListener()
int getOutlineAmbientShadowColor()
ViewOutlineProvider getOutlineProvider()
int getOutlineSpotShadowColor()
int getOverScrollMode()
ViewOverlay getOverlay()
int getPaddingBottom()
int getPaddingEnd()
int getPaddingLeft()
int getPaddingRight()
int getPaddingStart()
int getPaddingTop()
final ViewParent getParent()
ViewParent getParentForAccessibility()
float getPivotX()
float getPivotY()
PointerIcon getPointerIcon()
Resources getResources()
final boolean getRevealOnFocusHint()
final int getRight()
float getRightFadingEdgeStrength()
int getRightPaddingOffset()
View getRootView()
WindowInsets getRootWindowInsets()
float getRotation()
float getRotationX()
float getRotationY()
float getScaleX()
float getScaleY()
int getScrollBarDefaultDelayBeforeFade()
int getScrollBarFadeDuration()
int getScrollBarSize()
int getScrollBarStyle()
int getScrollIndicators()
final int getScrollX()
final int getScrollY()
int getSolidColor()
StateListAnimator getStateListAnimator()
int getSuggestedMinimumHeight()
int getSuggestedMinimumWidth()
int getSystemUiVisibility()
Object getTag()
Object getTag(int arg0)
int getTextAlignment()
int getTextDirection()
CharSequence getTooltipText()
final int getTop()
float getTopFadingEdgeStrength()
int getTopPaddingOffset()
TouchDelegate getTouchDelegate()
ArrayList<View> getTouchables()
String getTransitionName()
float getTranslationX()
float getTranslationY()
float getTranslationZ()
int getVerticalFadingEdgeLength()
int getVerticalScrollbarPosition()
int getVerticalScrollbarWidth()
ViewTreeObserver getViewTreeObserver()
int getVisibility()
final int getWidth()
int getWindowAttachCount()
WindowId getWindowId()
int getWindowSystemUiVisibility()
IBinder getWindowToken()
int getWindowVisibility()
void getWindowVisibleDisplayFrame(Rect arg0)
float getX()
float getY()
float getZ()
boolean hasExplicitFocusable()
boolean hasFocus()
boolean hasFocusable()
boolean hasNestedScrollingParent()
boolean hasOnClickListeners()
boolean hasOverlappingRendering()
boolean hasPointerCapture()
boolean hasTransientState()
boolean hasWindowFocus()
static View inflate(Context arg0, int arg1, ViewGroup arg2)
void invalidate()
void invalidate(Rect arg0)
void invalidate(int arg0, int arg1, int arg2, int arg3)
void invalidateDrawable(Drawable arg0)
void invalidateOutline()
boolean isAccessibilityFocused()
boolean isActivated()
boolean isAttachedToWindow()
boolean isClickable()
boolean isContextClickable()
boolean isDirty()
boolean isDrawingCacheEnabled()
boolean isDuplicateParentStateEnabled()
boolean isEnabled()
final boolean isFocusable()
final boolean isFocusableInTouchMode()
boolean isFocused()
final boolean isFocusedByDefault()
boolean isHapticFeedbackEnabled()
boolean isHardwareAccelerated()
boolean isHorizontalFadingEdgeEnabled()
boolean isHorizontalScrollBarEnabled()
boolean isHovered()
boolean isImportantForAccessibility()
final boolean isImportantForAutofill()
boolean isInEditMode()
boolean isInLayout()
boolean isInTouchMode()
final boolean isKeyboardNavigationCluster()
boolean isLaidOut()
boolean isLayoutDirectionResolved()
boolean isLayoutRequested()
boolean isLongClickable()
boolean isNestedScrollingEnabled()
boolean isOpaque()
boolean isPaddingOffsetRequired()
boolean isPaddingRelative()
boolean isPressed()
boolean isSaveEnabled()
boolean isSaveFromParentEnabled()
boolean isScreenReaderFocusable()
boolean isScrollContainer()
boolean isScrollbarFadingEnabled()
boolean isSelected()
boolean isShown()
boolean isSoundEffectsEnabled()
final boolean isTemporarilyDetached()
boolean isTextAlignmentResolved()
boolean isTextDirectionResolved()
boolean isVerticalFadingEdgeEnabled()
boolean isVerticalScrollBarEnabled()
boolean isVisibleToUserForAutofill(int arg0)
void jumpDrawablesToCurrentState()
View keyboardNavigationClusterSearch(View arg0, int arg1)
void layout(int arg0, int arg1, int arg2, int arg3)
final void measure(int arg0, int arg1)
static int[] mergeDrawableStates(int[] arg0, int[] arg1)
void offsetLeftAndRight(int arg0)
void offsetTopAndBottom(int arg0)
void onAnimationEnd()
void onAnimationStart()
WindowInsets onApplyWindowInsets(WindowInsets arg0)
void onAttachedToWindow()
void onCancelPendingInputEvents()
boolean onCapturedPointerEvent(MotionEvent arg0)
boolean onCheckIsTextEditor()
void onConfigurationChanged(Configuration arg0)
void onCreateContextMenu(ContextMenu arg0)
int[] onCreateDrawableState(int arg0)
InputConnection onCreateInputConnection(EditorInfo arg0)
void onDetachedFromWindow()
void onDisplayHint(int arg0)
boolean onDragEvent(DragEvent arg0)
void onDraw(Canvas arg0)
void onDrawForeground(Canvas arg0)
final void onDrawScrollBars(Canvas arg0)
boolean onFilterTouchEventForSecurity(MotionEvent arg0)
void onFinishInflate()
void onFinishTemporaryDetach()
void onFocusChanged(boolean arg0, int arg1, Rect arg2)
boolean onGenericMotionEvent(MotionEvent arg0)
void onHoverChanged(boolean arg0)
boolean onHoverEvent(MotionEvent arg0)
void onInitializeAccessibilityEvent(AccessibilityEvent arg0)
void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo arg0)
boolean onKeyDown(int arg0, KeyEvent arg1)
boolean onKeyFallback(KeyEvent arg0)
boolean onKeyLongPress(int arg0, KeyEvent arg1)
boolean onKeyMultiple(int arg0, int arg1, KeyEvent arg2)
boolean onKeyPreIme(int arg0, KeyEvent arg1)
boolean onKeyShortcut(int arg0, KeyEvent arg1)
boolean onKeyUp(int arg0, KeyEvent arg1)
void onLayout(boolean arg0, int arg1, int arg2, int arg3, int arg4)
void onMeasure(int arg0, int arg1)
void onOverScrolled(int arg0, int arg1, boolean arg2, boolean arg3)
void onPointerCaptureChange(boolean arg0)
void onPopulateAccessibilityEvent(AccessibilityEvent arg0)
void onProvideAutofillStructure(ViewStructure arg0, int arg1)
void onProvideAutofillVirtualStructure(ViewStructure arg0, int arg1)
void onProvideStructure(ViewStructure arg0)
void onProvideVirtualStructure(ViewStructure arg0)
PointerIcon onResolvePointerIcon(MotionEvent arg0, int arg1)
void onRestoreInstanceState(Parcelable arg0)
void onRtlPropertiesChanged(int arg0)
Parcelable onSaveInstanceState()
void onScreenStateChanged(int arg0)
void onScrollChanged(int arg0, int arg1, int arg2, int arg3)
boolean onSetAlpha(int arg0)
void onSizeChanged(int arg0, int arg1, int arg2, int arg3)
void onStartTemporaryDetach()
boolean onTouchEvent(MotionEvent arg0)
boolean onTrackballEvent(MotionEvent arg0)
void onVisibilityAggregated(boolean arg0)
void onVisibilityChanged(View arg0, int arg1)
void onWindowFocusChanged(boolean arg0)
void onWindowSystemUiVisibilityChanged(int arg0)
void onWindowVisibilityChanged(int arg0)
boolean overScrollBy(int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, boolean arg8)
boolean performAccessibilityAction(int arg0, Bundle arg1)
boolean performClick()
boolean performContextClick(float arg0, float arg1)
boolean performContextClick()
boolean performHapticFeedback(int arg0)
boolean performHapticFeedback(int arg0, int arg1)
boolean performLongClick(float arg0, float arg1)
boolean performLongClick()
void playSoundEffect(int arg0)
boolean post(Runnable arg0)
boolean postDelayed(Runnable arg0, long arg1)
void postInvalidate()
void postInvalidate(int arg0, int arg1, int arg2, int arg3)
void postInvalidateDelayed(long arg0, int arg1, int arg2, int arg3, int arg4)
void postInvalidateDelayed(long arg0)
void postInvalidateOnAnimation(int arg0, int arg1, int arg2, int arg3)
void postInvalidateOnAnimation()
void postOnAnimation(Runnable arg0)
void postOnAnimationDelayed(Runnable arg0, long arg1)
void refreshDrawableState()
void releasePointerCapture()
boolean removeCallbacks(Runnable arg0)
void removeKeyFallbackListener(View.OnKeyFallbackListener arg0)
void removeOnAttachStateChangeListener(View.OnAttachStateChangeListenerarg0)
void removeOnLayoutChangeListener(View.OnLayoutChangeListener arg0)
void requestApplyInsets()
void requestFitSystemWindows()
final boolean requestFocus(int arg0)
final boolean requestFocus()
boolean requestFocus(int arg0, Rect arg1)
final boolean requestFocusFromTouch()
void requestLayout()
void requestPointerCapture()
boolean requestRectangleOnScreen(Rect arg0)
boolean requestRectangleOnScreen(Rect arg0, boolean arg1)
final void requestUnbufferedDispatch(MotionEvent arg0)
final <T extends View> T requireViewById(int arg0)
static int resolveSize(int arg0, int arg1)
static int resolveSizeAndState(int arg0, int arg1, int arg2)
boolean restoreDefaultFocus()
void restoreHierarchyState(SparseArray<Parcelable> arg0)
void saveHierarchyState(SparseArray<Parcelable> arg0)
void scheduleDrawable(Drawable arg0, Runnable arg1, long arg2)
void scrollBy(int arg0, int arg1)
void scrollTo(int arg0, int arg1)
void sendAccessibilityEvent(int arg0)
void sendAccessibilityEventUnchecked(AccessibilityEvent arg0)
void setAccessibilityDelegate(View.AccessibilityDelegate arg0)
void setAccessibilityLiveRegion(int arg0)
void setAccessibilityPaneTitle(CharSequence arg0)
void setAccessibilityTraversalAfter(int arg0)
void setAccessibilityTraversalBefore(int arg0)
void setActivated(boolean arg0)
void setAlpha(float arg0)
void setAnimation(Animation arg0)
void setAutofillHints(String... arg0)
void setBackground(Drawable arg0)
void setBackgroundColor(int arg0)
void setBackgroundDrawable(Drawable arg0)
void setBackgroundResource(int arg0)
void setBackgroundTintList(ColorStateList arg0)
void setBackgroundTintMode(PorterDuff.Mode arg0)
final void setBottom(int arg0)
void setCameraDistance(float arg0)
void setClickable(boolean arg0)
void setClipBounds(Rect arg0)
void setClipToOutline(boolean arg0)
void setContentDescription(CharSequence arg0)
void setContextClickable(boolean arg0)
void setDefaultFocusHighlightEnabled(boolean arg0)
void setDrawingCacheBackgroundColor(int arg0)
void setDrawingCacheEnabled(boolean arg0)
void setDrawingCacheQuality(int arg0)
void setDuplicateParentStateEnabled(boolean arg0)
void setElevation(float arg0)
void setEnabled(boolean arg0)
void setFadingEdgeLength(int arg0)
void setFilterTouchesWhenObscured(boolean arg0)
void setFitsSystemWindows(boolean arg0)
void setFocusable(boolean arg0)
void setFocusable(int arg0)
void setFocusableInTouchMode(boolean arg0)
void setFocusedByDefault(boolean arg0)
void setForeground(Drawable arg0)
void setForegroundGravity(int arg0)
void setForegroundTintList(ColorStateList arg0)
void setForegroundTintMode(PorterDuff.Mode arg0)
void setHapticFeedbackEnabled(boolean arg0)
void setHasTransientState(boolean arg0)
void setHorizontalFadingEdgeEnabled(boolean arg0)
void setHorizontalScrollBarEnabled(boolean arg0)
void setHovered(boolean arg0)
void setId(int arg0)
void setImportantForAccessibility(int arg0)
void setImportantForAutofill(int arg0)
void setKeepScreenOn(boolean arg0)
void setKeyboardNavigationCluster(boolean arg0)
void setLabelFor(int arg0)
void setLayerPaint(Paint arg0)
void setLayerType(int arg0, Paint arg1)
void setLayoutDirection(int arg0)
void setLayoutParams(ViewGroup.LayoutParams arg0)
final void setLeft(int arg0)
void setLongClickable(boolean arg0)
final void setMeasuredDimension(int arg0, int arg1)
void setMinimumHeight(int arg0)
void setMinimumWidth(int arg0)
void setNestedScrollingEnabled(boolean arg0)
void setNextClusterForwardId(int arg0)
void setNextFocusDownId(int arg0)
void setNextFocusForwardId(int arg0)
void setNextFocusLeftId(int arg0)
void setNextFocusRightId(int arg0)
void setNextFocusUpId(int arg0)
void setOnApplyWindowInsetsListener(View.OnApplyWindowInsetsListener arg0)
void setOnCapturedPointerListener(View.OnCapturedPointerListener arg0)
void setOnClickListener(View.OnClickListener arg0)
void setOnContextClickListener(View.OnContextClickListener arg0)
void setOnCreateContextMenuListener(View.OnCreateContextMenuListener arg0)
void setOnDragListener(View.OnDragListener arg0)
void setOnFocusChangeListener(View.OnFocusChangeListener arg0)
void setOnGenericMotionListener(View.OnGenericMotionListener arg0)
void setOnHoverListener(View.OnHoverListener arg0)
void setOnKeyListener(View.OnKeyListener arg0)
void setOnLongClickListener(View.OnLongClickListener arg0)
void setOnScrollChangeListener(View.OnScrollChangeListener arg0)
void setOnSystemUiVisibilityChangeListener(View.OnSystemUiVisibilityChangeListener arg0)
void setOnTouchListener(View.OnTouchListener arg0)
void setOutlineAmbientShadowColor(int arg0)
void setOutlineProvider(ViewOutlineProvider arg0)
void setOutlineSpotShadowColor(int arg0)
void setOverScrollMode(int arg0)
void setPadding(int arg0, int arg1, int arg2, int arg3)
void setPaddingRelative(int arg0, int arg1, int arg2, int arg3)
void setPivotX(float arg0)
void setPivotY(float arg0)
void setPointerIcon(PointerIcon arg0)
void setPressed(boolean arg0)
final void setRevealOnFocusHint(boolean arg0)
final void setRight(int arg0)
void setRotation(float arg0)
void setRotationX(float arg0)
void setRotationY(float arg0)
void setSaveEnabled(boolean arg0)
void setSaveFromParentEnabled(boolean arg0)
void setScaleX(float arg0)
void setScaleY(float arg0)
void setScreenReaderFocusable(boolean arg0)
void setScrollBarDefaultDelayBeforeFade(int arg0)
void setScrollBarFadeDuration(int arg0)
void setScrollBarSize(int arg0)
void setScrollBarStyle(int arg0)
void setScrollContainer(boolean arg0)
void setScrollIndicators(int arg0, int arg1)
void setScrollIndicators(int arg0)
void setScrollX(int arg0)
void setScrollY(int arg0)
void setScrollbarFadingEnabled(boolean arg0)
void setSelected(boolean arg0)
void setSoundEffectsEnabled(boolean arg0)
void setStateListAnimator(StateListAnimator arg0)
void setSystemUiVisibility(int arg0)
void setTag(int arg0, Object arg1)
void setTag(Object arg0)
void setTextAlignment(int arg0)
void setTextDirection(int arg0)
void setTooltipText(CharSequence arg0)
final void setTop(int arg0)
void setTouchDelegate(TouchDelegate arg0)
final void setTransitionName(String arg0)
void setTranslationX(float arg0)
void setTranslationY(float arg0)
void setTranslationZ(float arg0)
void setVerticalFadingEdgeEnabled(boolean arg0)
void setVerticalScrollBarEnabled(boolean arg0)
void setVerticalScrollbarPosition(int arg0)
void setVisibility(int arg0)
void setWillNotCacheDrawing(boolean arg0)
void setWillNotDraw(boolean arg0)
void setX(float arg0)
void setY(float arg0)
void setZ(float arg0)
boolean showContextMenu()
boolean showContextMenu(float arg0, float arg1)
ActionMode startActionMode(ActionMode.Callback arg0, int arg1)
ActionMode startActionMode(ActionMode.Callback arg0)
void startAnimation(Animation arg0)
final boolean startDrag(ClipData arg0, View.DragShadowBuilder arg1, Object arg2, int arg3)
final boolean startDragAndDrop(ClipData arg0, View.DragShadowBuilder arg1, Object arg2, int arg3)
boolean startNestedScroll(int arg0)
void stopNestedScroll()
String toString()
void unscheduleDrawable(Drawable arg0, Runnable arg1)
void unscheduleDrawable(Drawable arg0)
final void updateDragShadow(View.DragShadowBuilder arg0)
boolean verifyDrawable(Drawable arg0)
boolean willNotCacheDrawing()
boolean willNotDraw()
From class java.lang.Object
Object clone()
boolean equals(Object arg0)
void finalize()
final Class<?> getClass()
int hashCode()
final void notify()
final void notifyAll()
String toString()
final void wait(long arg0, int arg1)
final void wait(long arg0)
final void wait()
From interface android.view.ViewParent
abstract void bringChildToFront(View arg0)
abstract boolean canResolveLayoutDirection()
abstract boolean canResolveTextAlignment()
abstract boolean canResolveTextDirection()
abstract void childDrawableStateChanged(View arg0)
abstract void childHasTransientStateChanged(View arg0, boolean arg1)
abstract void clearChildFocus(View arg0)
abstract void createContextMenu(ContextMenu arg0)
abstract View focusSearch(View arg0, int arg1)
abstract void focusableViewAvailable(View arg0)
abstract boolean getChildVisibleRect(View arg0, Rect arg1, Point arg2)
abstract int getLayoutDirection()
abstract ViewParent getParent()
abstract ViewParent getParentForAccessibility()
abstract int getTextAlignment()
abstract int getTextDirection()
abstract void invalidateChild(View arg0, Rect arg1)
abstract ViewParent invalidateChildInParent(int[] arg0, Rect arg1)
abstract boolean isLayoutDirectionResolved()
abstract boolean isLayoutRequested()
abstract boolean isTextAlignmentResolved()
abstract boolean isTextDirectionResolved()
abstract View keyboardNavigationClusterSearch(View arg0, int arg1)
abstract void notifySubtreeAccessibilityStateChanged(View arg0, View arg1, int arg2)
default void onDescendantInvalidated(View arg0, View arg1)
abstract boolean onNestedFling(View arg0, float arg1, float arg2, boolean arg3)
abstract boolean onNestedPreFling(View arg0, float arg1, float arg2)
abstract boolean onNestedPrePerformAccessibilityAction(View arg0, int arg1, Bundle arg2)
abstract void onNestedPreScroll(View arg0, int arg1, int arg2, int[] arg3)
abstract void onNestedScroll(View arg0, int arg1, int arg2, int arg3, int arg4)
abstract void onNestedScrollAccepted(View arg0, View arg1, int arg2)
abstract boolean onStartNestedScroll(View arg0, View arg1, int arg2)
abstract void onStopNestedScroll(View arg0)
abstract void recomputeViewAttributes(View arg0)
abstract void requestChildFocus(View arg0, View arg1)
abstract boolean requestChildRectangleOnScreen(View arg0, Rect arg1, boolean arg2)
abstract void requestDisallowInterceptTouchEvent(boolean arg0)
abstract void requestFitSystemWindows()
abstract void requestLayout()
abstract boolean requestSendAccessibilityEvent(View arg0, AccessibilityEvent arg1)
abstract void requestTransparentRegion(View arg0)
abstract boolean showContextMenuForChild(View arg0)
abstract boolean showContextMenuForChild(View arg0, float arg1, float arg2)
abstract ActionMode startActionModeForChild(View arg0, ActionMode.Callback arg1, int arg2)
abstract ActionMode startActionModeForChild(View arg0, ActionMode.Callback arg1)
From interface android.view.ViewManager
abstract void addView(View arg0, ViewGroup.LayoutParams arg1)
abstract void removeView(View arg0)
abstract void updateViewLayout(View arg0, ViewGroup.LayoutParams arg1)
From interface android.graphics.drawable.Drawable.Callback
abstract void invalidateDrawable(Drawable arg0)
abstract void scheduleDrawable(Drawable arg0, Runnable arg1, long arg2)
abstract void unscheduleDrawable(Drawable arg0, Runnable arg1)
From interface android.view.KeyEvent.Callback
abstract boolean onKeyDown(int arg0, KeyEvent arg1)
abstract boolean onKeyLongPress(int arg0, KeyEvent arg1)
abstract boolean onKeyMultiple(int arg0, int arg1, KeyEvent arg2)
abstract boolean onKeyUp(int arg0, KeyEvent arg1)
From interface android.view.accessibility.AccessibilityEventSource
abstract void sendAccessibilityEvent(int arg0)
abstract void sendAccessibilityEventUnchecked(AccessibilityEvent arg0)
From interface android.support.v4.view.ScrollingView
abstract int computeHorizontalScrollExtent()

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

abstract int computeHorizontalScrollOffset()

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

abstract int computeHorizontalScrollRange()

Compute the horizontal range that the horizontal scrollbar represents.

abstract int computeVerticalScrollExtent()

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

abstract int computeVerticalScrollOffset()

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

abstract int computeVerticalScrollRange()

Compute the vertical range that the vertical scrollbar represents.

From interface android.support.v4.view.NestedScrollingChild2
abstract 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.

abstract boolean dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed,int dyUnconsumed, int[] offsetInWindow, int type)

Dispatch one step of a nested scroll in progress.

abstract boolean hasNestedScrollingParent(int type)

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

abstract boolean startNestedScroll(int axes, int type)

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

abstract void stopNestedScroll(int type)

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

From interface android.support.v4.view.NestedScrollingChild
abstract boolean dispatchNestedFling(float velocityX, float velocityY, boolean consumed)

Dispatch a fling to a nested scrolling parent.

abstract boolean dispatchNestedPreFling(float velocityX, float velocityY)

Dispatch a fling to a nested scrolling parent before it is processed by this view.

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

abstract boolean dispatchNestedScroll(int dxConsumed, int dyConsumed, int dxUnconsumed,int dyUnconsumed, int[] offsetInWindow)

Dispatch one step of a nested scroll in progress.

abstract boolean hasNestedScrollingParent()

Returns true if this view has a nested scrolling parent.

abstract boolean isNestedScrollingEnabled()

Returns true if nested scrolling is enabled for this view.

abstract void setNestedScrollingEnabled(boolean enabled)

Enable or disable nested scrolling for this view.

abstract boolean startNestedScroll(int axes)

Begin a nestable scroll operation along the given axes.

abstract void stopNestedScroll()

Stop a nested scroll in progress.

XML attributes

RecyclerView_layoutManager

Constants

HORIZONTAL

added in version 22.1.0

 

int HORIZONTAL

Constant Value: 0 (0x00000000)

INVALID_TYPE

added in version 22.1.0

 

int INVALID_TYPE

Constant Value: -1 (0xffffffff)

NO_ID

added in version 22.1.0

 

long NO_ID

Constant Value: -1 (0xffffffffffffffff)

NO_POSITION

added in version 22.1.0

 

int NO_POSITION

Constant Value: -1 (0xffffffff)

SCROLL_STATE_DRAGGING

added in version 22.1.0

 

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

added in version 22.1.0

 

int SCROLL_STATE_IDLE

The RecyclerView is not currently scrolling.

See also:

Constant Value: 0 (0x00000000)

SCROLL_STATE_SETTLING

added in version 22.1.0

 

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

added in version 22.1.0

 

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

added in version 22.1.0

 

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)

VERTICAL

added in version 22.1.0

 

int VERTICAL

Constant Value: 1 (0x00000001)

Public constructors

RecyclerView

added in version 22.1.0

 

RecyclerView (Context context)

Parameters
context Context

RecyclerView

added in version 22.1.0

 

RecyclerView (Context context, AttributeSet attrs)

Parameters
context Context
attrs AttributeSet

RecyclerView

added in version 22.1.0

 

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

added in version 22.1.0

 

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

added in version 22.1.0

 

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

added in version 24.1.0

 

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

added in version 22.1.0

 

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 fromonInterceptTouchEvent(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

added in version 22.1.0

 

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

added in version 24.1.0

 

void clearOnChildAttachStateChangeListeners ()

Removes all listeners that were added viaaddOnChildAttachStateChangeListener(OnChildAttachStateChangeListener).

clearOnScrollListeners

added in version 22.1.0

 

void clearOnScrollListeners ()

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

computeHorizontalScrollExtent

added in version 22.1.0

 

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 bycomputeHorizontalScrollRange() 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

See also:

computeHorizontalScrollOffset

added in version 22.1.0

 

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 bycomputeHorizontalScrollRange() 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

added in version 22.1.0

 

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 bycomputeHorizontalScrollExtent() 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

See also:

computeVerticalScrollExtent

added in version 22.1.0

 

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

See also:

computeVerticalScrollOffset

added in version 22.1.0

 

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

added in version 22.1.0

 

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

See also:

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

added in version 26.1.0

 

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

added in version 26.1.0

 

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

draw

 

void draw (Canvas c)

Parameters
c Canvas

drawChild

added in version 24.1.0

 

boolean drawChild (Canvas canvas, View child, long drawingTime)

Parameters
canvas Canvas
child View
drawingTime long
Returns
boolean

findChildViewUnder

added in version 22.1.0

 

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

added in version 24.1.0

 

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.

See also:

findContainingViewHolder

added in version 24.1.0

 

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

added in version 22.1.0

 

RecyclerView.ViewHolder findViewHolderForAdapterPosition (int position)

Return the ViewHolder for the item in the given position of the data set. UnlikefindViewHolderForLayoutPosition(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

added in version 22.1.0

 

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

added in version 22.1.0

 

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

added in version 22.1.0

 

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

added in version 22.1.0

 

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.

See also:

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_UPFOCUS_DOWNFOCUS_LEFTFOCUS_RIGHTFOCUS_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

added in version 22.1.0

 

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

added in version 22.1.0

 

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

added in version 22.1.0

 

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

added in version 22.1.0

 

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

added in version 22.1.0

 

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

added in version 22.1.0

 

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

added in version 22.1.0

 

RecyclerViewAccessibilityDelegate getCompatAccessibilityDelegate ()

Returns the accessibility delegate compatibility implementation used by the RecyclerView.

Returns
RecyclerViewAccessibilityDelegate An instance of AccessibilityDelegateCompat used by RecyclerView

getDecoratedBoundsWithMargins

added in version 25.1.0

 

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

added in version 27.1.0

 

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

added in version 22.1.0

 

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

added in version 26.1.0

 

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

added in version 27.1.0

 

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

added in version 22.1.0

 

RecyclerView.LayoutManager getLayoutManager ()

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

Returns
RecyclerView.LayoutManager The currently bound LayoutManager

getMaxFlingVelocity

added in version 24.1.0

 

int getMaxFlingVelocity ()

Returns the maximum fling velocity used by this RecyclerView.

Returns
int The maximum fling velocity used by this RecyclerView.

getMinFlingVelocity

added in version 24.1.0

 

int getMinFlingVelocity ()

Returns the minimum velocity to start a fling.

Returns
int The minimum velocity to start a fling

getOnFlingListener

added in version 25.1.0

 

RecyclerView.OnFlingListener getOnFlingListener ()

Get the current RecyclerView.OnFlingListener from this RecyclerView.

Returns
RecyclerView.OnFlingListener The RecyclerView.OnFlingListener instance currently set (can be null).

getPreserveFocusAfterLayout

added in version 24.1.0

 

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

added in version 22.1.0

 

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

added in version 22.1.0

 

int getScrollState ()

Return the current scrolling state of the RecyclerView.

Returns
int SCROLL_STATE_IDLESCROLL_STATE_DRAGGING or SCROLL_STATE_SETTLING

hasFixedSize

added in version 22.1.0

 

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

added in version 26.1.0

 

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

added in version 22.1.0

 

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 RecyclerView has not yet calculated the first layout after it is attached to the Window or the Adapter has been replaced.

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

invalidateItemDecorations

added in version 22.1.0

 

void invalidateItemDecorations ()

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

isAnimating

added in version 24.1.0

 

boolean isAnimating ()

Returns true if RecyclerView is currently running some animations.

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

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

isAttachedToWindow

 

boolean isAttachedToWindow ()

Returns true if RecyclerView is attached to window.

Returns
boolean

isComputingLayout

added in version 24.1.0

 

boolean isComputingLayout ()

Returns whether RecyclerView is currently computing a layout.

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

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

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

Returns
boolean true if RecyclerView is currently computing a layout, false otherwise

isLayoutFrozen

added in version 24.1.0

 

boolean isLayoutFrozen ()

Returns true if layout and scroll are frozen.

Returns
boolean true if layout and scroll are frozen

See also:

isNestedScrollingEnabled

 

boolean isNestedScrollingEnabled ()

Returns
boolean

offsetChildrenHorizontal

added in version 22.1.0

 

void offsetChildrenHorizontal (int dx)

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

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

offsetChildrenVertical

added in version 22.1.0

 

void offsetChildrenVertical (int dy)

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

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

onChildAttachedToWindow

added in version 22.1.0

 

void onChildAttachedToWindow (View child)

Called when an item view is attached to this RecyclerView.

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

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

onChildDetachedFromWindow

added in version 22.1.0

 

void onChildDetachedFromWindow (View child)

Called when an item view is detached from this RecyclerView.

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

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

onDraw

added in version 22.1.0

 

void onDraw (Canvas c)

Parameters
c Canvas

onGenericMotionEvent

 

boolean onGenericMotionEvent (MotionEvent event)

Parameters
event MotionEvent
Returns
boolean

onInterceptTouchEvent

 

boolean onInterceptTouchEvent (MotionEvent e)

Parameters
e MotionEvent
Returns
boolean

onScrollStateChanged

added in version 22.1.0

 

void onScrollStateChanged (int state)

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

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

Parameters
state int: the new scroll state, one of SCROLL_STATE_IDLESCROLL_STATE_DRAGGING or SCROLL_STATE_SETTLING

onScrolled

added in version 22.1.0

 

void onScrolled (int dx, int dy)

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

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

This differs from onScrollChanged(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 getScrollX()and getScrollY() values which do not correspond to the data set scroll position. However, some subclasses may choose to use these fields as special offsets.

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

onTouchEvent

 

boolean onTouchEvent (MotionEvent e)

Parameters
e MotionEvent
Returns
boolean

removeItemDecoration

added in version 22.1.0

 

void removeItemDecoration (RecyclerView.ItemDecoration decor)

Remove an RecyclerView.ItemDecoration from this RecyclerView.

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

Parameters
decor RecyclerView.ItemDecoration: Decoration to remove

See also:

removeItemDecorationAt

added in version 27.1.0

 

void removeItemDecorationAt (int index)

Removes the RecyclerView.ItemDecoration associated with the supplied index position.

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

removeOnChildAttachStateChangeListener

added in version 24.1.0

 

void removeOnChildAttachStateChangeListener (RecyclerView.OnChildAttachStateChangeListener listener)

Removes the provided listener from child attached state listeners list.

Parameters
listener RecyclerView.OnChildAttachStateChangeListener: Listener to unregister

removeOnItemTouchListener

added in version 22.1.0

 

void removeOnItemTouchListener (RecyclerView.OnItemTouchListener listener)

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

Parameters
listener RecyclerView.OnItemTouchListener: Listener to remove

removeOnScrollListener

added in version 22.1.0

 

void removeOnScrollListener (RecyclerView.OnScrollListener listener)

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

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

requestChildFocus

 

void requestChildFocus (View child, View focused)

Parameters
child View
focused View

requestChildRectangleOnScreen

 

boolean requestChildRectangleOnScreen (View child, Rect rect, boolean immediate)

Parameters
child View
rect Rect
immediate boolean
Returns
boolean

requestDisallowInterceptTouchEvent

 

void requestDisallowInterceptTouchEvent (boolean disallowIntercept)

Parameters
disallowIntercept boolean

requestLayout

 

void requestLayout ()

scrollBy

 

void scrollBy (int x, int y)

Parameters
x int
y int

scrollTo

 

void scrollTo (int x, int y)

Parameters
x int
y int

scrollToPosition

added in version 22.1.0

 

void scrollToPosition (int position)

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

Parameters
position int: Scroll to this adapter position

See also:

sendAccessibilityEventUnchecked

 

void sendAccessibilityEventUnchecked (AccessibilityEvent event)

Parameters
event AccessibilityEvent

setAccessibilityDelegateCompat

added in version 22.1.0

 

void setAccessibilityDelegateCompat (RecyclerViewAccessibilityDelegate accessibilityDelegate)

Sets the accessibility delegate compatibility implementation used by RecyclerView.

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

setAdapter

added in version 22.1.0

 

void setAdapter (Adapter adapter)

Set a new adapter to provide child views on demand.

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

Parameters
adapter Adapter: The new adapter to set, or null to set no adapter.

See also:

setChildDrawingOrderCallback

added in version 24.1.0

 

void setChildDrawingOrderCallback (RecyclerView.ChildDrawingOrderCallback childDrawingOrderCallback)

Sets the RecyclerView.ChildDrawingOrderCallback to be used for drawing children.

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

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

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

setClipToPadding

 

void setClipToPadding (boolean clipToPadding)

Parameters
clipToPadding boolean

setEdgeEffectFactory

added in version 27.1.0

 

void setEdgeEffectFactory (RecyclerView.EdgeEffectFactory edgeEffectFactory)

Set a RecyclerView.EdgeEffectFactory for this RecyclerView.

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

Parameters
edgeEffectFactory RecyclerView.EdgeEffectFactory: The RecyclerView.EdgeEffectFactory instance.

setHasFixedSize

added in version 22.1.0

 

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. RecyclerView can still change its size based on other factors (e.g. its parent's size) but this size calculation cannot depend on the size of its children or contents of its adapter (except the number of items in the adapter).

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

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

setItemAnimator

added in version 22.1.0

 

void setItemAnimator (RecyclerView.ItemAnimator animator)

Sets the 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.

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

setItemViewCacheSize

added in version 22.1.0

 

void setItemViewCacheSize (int size)

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

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

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

setLayoutFrozen

added in version 24.1.0

 

void setLayoutFrozen (boolean frozen)

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

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

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

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

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

setLayoutManager

added in version 22.1.0

 

void setLayoutManager (RecyclerView.LayoutManager layout)

Set the 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.

Parameters
layout RecyclerView.LayoutManager: LayoutManager to use

setNestedScrollingEnabled

 

void setNestedScrollingEnabled (boolean enabled)

Parameters
enabled boolean

setOnFlingListener

added in version 25.1.0

 

void setOnFlingListener (RecyclerView.OnFlingListener onFlingListener)

Set a 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.

Parameters
onFlingListener RecyclerView.OnFlingListener: The RecyclerView.OnFlingListener instance.

setOnScrollListener

added in version 22.1.0

 

void setOnScrollListener (RecyclerView.OnScrollListener listener)

This method was deprecated in API level 22.1.0.
Use addOnScrollListener(OnScrollListener) and removeOnScrollListener(OnScrollListener)

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

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

setPreserveFocusAfterLayout

added in version 24.1.0

 

void setPreserveFocusAfterLayout (boolean preserveFocusAfterLayout)

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

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

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

See also:

setRecycledViewPool

added in version 22.1.0

 

void setRecycledViewPool (RecyclerView.RecycledViewPool pool)

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

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

setRecyclerListener

added in version 22.1.0

 

void setRecyclerListener (RecyclerView.RecyclerListener listener)

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

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

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

setScrollingTouchSlop

added in version 22.1.0

 

void setScrollingTouchSlop (int slopConstant)

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

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

setViewCacheExtension

added in version 22.1.0

 

void setViewCacheExtension (RecyclerView.ViewCacheExtension extension)

Sets a new RecyclerView.ViewCacheExtension to be used by the Recycler.

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

See also:

smoothScrollBy

added in version 22.1.0

 

void smoothScrollBy (int dx, int dy)

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

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

smoothScrollBy

added in version 25.1.0

 

void smoothScrollBy (int dx, int dy, Interpolator interpolator)

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

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

smoothScrollToPosition

added in version 22.1.0

 

void smoothScrollToPosition (int position)

Starts a smooth scroll to an adapter position.

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

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

Parameters
position int: The adapter position to scroll to

See also:

startNestedScroll

 

boolean startNestedScroll (int axes)

Parameters
axes int
Returns
boolean

startNestedScroll

added in version 26.1.0

 

boolean startNestedScroll (int axes, int type)

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

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

The view will call startNestedScroll upon initiating a scroll operation. In the case of a touch scroll type this corresponds to the initial ACTION_DOWN. In the case of touch scrolling the nested scroll will be terminated automatically in the same manner as requestDisallowInterceptTouchEvent(boolean). In the event of programmatic scrolling the caller must explicitly call stopNestedScroll(int) 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. SeeonNestedScroll(View, int, int, int, int, int).

Parameters
axes int: Flags consisting of a combination of SCROLL_AXIS_HORIZONTAL and/or SCROLL_AXIS_VERTICAL.
type int: the type of input which cause this scroll event
Returns
boolean true if a cooperative parent was found and nested scrolling has been enabled for the current gesture.

stopNestedScroll

 

void stopNestedScroll ()

stopNestedScroll

added in version 26.1.0

 

void stopNestedScroll (int type)

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

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

Parameters
type int: the type of input which cause this scroll event

stopScroll

added in version 22.1.0

 

void stopScroll ()

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

swapAdapter

added in version 22.1.0

 

void swapAdapter (Adapter adapter, boolean removeAndRecycleExistingViews)

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

Note that it still calls onAdapterChanged callbacks.

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

See also:

Protected methods

checkLayoutParams

 

boolean checkLayoutParams (ViewGroup.LayoutParams p)

Parameters
p ViewGroup.LayoutParams
Returns
boolean

dispatchRestoreInstanceState

 

void dispatchRestoreInstanceState (SparseArray<Parcelable> container)

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

Parameters
container SparseArray

dispatchSaveInstanceState

 

void dispatchSaveInstanceState (SparseArray<Parcelable> container)

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

Parameters
container SparseArray

generateDefaultLayoutParams

 

ViewGroup.LayoutParams generateDefaultLayoutParams ()

Returns
ViewGroup.LayoutParams

generateLayoutParams

 

ViewGroup.LayoutParams generateLayoutParams (ViewGroup.LayoutParams p)

Parameters
p ViewGroup.LayoutParams
Returns
ViewGroup.LayoutParams

getChildDrawingOrder

 

int getChildDrawingOrder (int childCount, int i)

Parameters
childCount int
i int
Returns
int

onAttachedToWindow

 

void onAttachedToWindow ()

onDetachedFromWindow

 

void onDetachedFromWindow ()

onLayout

added in version 22.1.0

 

void onLayout (boolean changed, int l, int t, int r, int b)

Parameters
changed boolean
l int
t int
r int
b int

onMeasure

 

void onMeasure (int widthSpec, int heightSpec)

Parameters
widthSpec int
heightSpec int

onRequestFocusInDescendants

 

boolean onRequestFocusInDescendants (int direction, Rect previouslyFocusedRect)

Parameters
direction int
previouslyFocusedRect Rect
Returns
boolean

onRestoreInstanceState

 

void onRestoreInstanceState (Parcelable state)

Parameters
state Parcelable

onSaveInstanceState

 

Parcelable onSaveInstanceState ()

Returns
Parcelable

onSizeChanged

 

void onSizeChanged (int w, int h, int oldw, int oldh)

Parameters
w int
h int
oldw int
oldh int

removeDetachedView

 

void removeDetachedView (View child, boolean animate)

Parameters
child View
animate boolean

猜你喜欢

转载自blog.csdn.net/u011038298/article/details/84846481