java.lang.Object | |||
↳ | android.view.View | ||
↳ | android.view.ViewGroup | ||
↳ | android.support.v7.widget.RecyclerView |
Known Direct Subclasses |
A flexible view for providing a limited window into a large data set.
RecyclerView.Adapter
responsible for providing views
that represent items in a data set.getChildAt(int)
. Contrast with Position.
RecyclerView introduces an additional level of abstraction between the RecyclerView.Adapter
and
RecyclerView.LayoutManager
to be able to detect data set changes in batches during a layout
calculation. This saves LayoutManager from tracking adapter changes to calculate animations.
It also helps with performance because all view bindings happen at the same time and unnecessary
bindings are avoided.
For this reason, there are two types of position
related methods in RecyclerView:
These two positions are the same except the time between dispatching adapter.notify*
events and calculating the updated layout.
Methods that return or receive *LayoutPosition*
use position as of the latest
layout calculation (e.g. 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.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
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.AdapterDataObserver |
Observer base class for watching changes to an RecyclerView.Adapter .
|
||||||||||
RecyclerView.ItemAnimator | This class defines the animations that take place on items as changes are made to the adapter. | ||||||||||
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. | ||||||||||
RecyclerView.LayoutManager |
A LayoutManager is responsible for measuring and positioning item views
within a RecyclerView as well as determining the policy for when to recycle
item views that are no longer visible to the user.
|
||||||||||
RecyclerView.LayoutParams |
LayoutParams subclass for children of
RecyclerView .
|
||||||||||
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. | ||||||||||
RecyclerView.OnScrollListener | An OnScrollListener can be set on a RecyclerView to receive messages when a scrolling event has occurred on that RecyclerView. | ||||||||||
RecyclerView.RecycledViewPool | RecycledViewPool lets you share Views between multiple RecyclerViews. | ||||||||||
RecyclerView.Recycler | A Recycler is responsible for managing scrapped or detached item views for reuse. | ||||||||||
RecyclerView.RecyclerListener | A RecyclerListener can be set on a RecyclerView to receive messages whenever a view is recycled. | ||||||||||
RecyclerView.SmoothScroller |
Base class for smooth scrolling. |
||||||||||
RecyclerView.State |
Contains useful information about the current RecyclerView state like target scroll position or view focus. |
||||||||||
RecyclerView.ViewCacheExtension | ViewCacheExtension is a helper class to provide an additional layer of view caching that can ben controlled by the developer. | ||||||||||
RecyclerView.ViewHolder | A ViewHolder describes an item view and metadata about its place within the RecyclerView. |
[Expand]
Inherited XML Attributes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.view.ViewGroup
| |||||||||||
From class
android.view.View
|
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 |
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.view.ViewGroup
| |||||||||||
From class
android.view.View
|
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.view.View
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adds any focusable views that are descendants of this view (possibly
including this view if it is focusable itself) to views.
| |||||||||||
Add an
RecyclerView.ItemDecoration to this RecyclerView.
| |||||||||||
Add an
RecyclerView.ItemDecoration to this RecyclerView.
| |||||||||||
Add an
RecyclerView.OnItemTouchListener to intercept touch events before they are dispatched
to child views or this view's standard scrolling behavior.
| |||||||||||
Compute the horizontal extent of the horizontal scrollbar's thumb within the horizontal range. | |||||||||||
Compute the horizontal offset of the horizontal scrollbar's thumb within the horizontal range. | |||||||||||
Compute the horizontal range that the horizontal scrollbar represents. | |||||||||||
Compute the vertical extent of the vertical scrollbar's thumb within the vertical range. | |||||||||||
Compute the vertical offset of the vertical scrollbar's thumb within the vertical range. | |||||||||||
Compute the vertical range that the vertical scrollbar represents. | |||||||||||
Manually render this view (and all of its children) to the given Canvas.
| |||||||||||
Find the topmost view under the given point.
| |||||||||||
Return the ViewHolder for the item in the given position of the data set.
| |||||||||||
Return the ViewHolder for the item with the given id.
| |||||||||||
Return the ViewHolder for the item in the given position of the data set as of the latest
layout pass.
| |||||||||||
This method is deprecated.
use
findViewHolderForLayoutPosition(int) or
findViewHolderForAdapterPosition(int)
| |||||||||||
Begin a standard fling with an initial velocity along each axis in pixels per second.
| |||||||||||
Find the nearest view in the specified direction that wants to take
focus.
| |||||||||||
Returns a new set of layout parameters based on the supplied attributes set.
| |||||||||||
Retrieves the previously set adapter or null if no adapter is set.
| |||||||||||
Return the adapter position that the given child view corresponds to.
| |||||||||||
Return the stable item id that the given child view corresponds to.
| |||||||||||
Return the adapter position of the given child view as of the latest completed layout pass.
| |||||||||||
This method is deprecated.
use
getChildAdapterPosition(View) or
getChildLayoutPosition(View) .
| |||||||||||
Retrieve the
RecyclerView.ViewHolder for the given child view.
| |||||||||||
Returns the accessibility delegate compatibility implementation used by the RecyclerView.
| |||||||||||
Gets the current ItemAnimator for this RecyclerView.
| |||||||||||
Return the
RecyclerView.LayoutManager currently responsible for
layout policy for this RecyclerView.
| |||||||||||
Retrieve this RecyclerView's
RecyclerView.RecycledViewPool .
| |||||||||||
Return the current scrolling state of the RecyclerView.
| |||||||||||
Invalidates all ItemDecorations.
| |||||||||||
Offset the bounds of all child views by
dx pixels.
| |||||||||||
Offset the bounds of all child views by
dy pixels.
| |||||||||||
Called when an item view is attached to this RecyclerView.
| |||||||||||
Called when an item view is detached from this RecyclerView.
| |||||||||||
Implement this to do your drawing.
| |||||||||||
Implement this method to handle generic motion events.
| |||||||||||
Implement this method to intercept all touch screen motion events.
| |||||||||||
Implement this method to handle touch screen motion events.
| |||||||||||
Remove an
RecyclerView.ItemDecoration from this RecyclerView.
| |||||||||||
Remove an
RecyclerView.OnItemTouchListener .
| |||||||||||
Called when a child of this parent wants focus
| |||||||||||
Called when a child of this group wants a particular rectangle to be
positioned onto the screen.
| |||||||||||
Call this when something has changed which has invalidated the
layout of this view.
| |||||||||||
Move the scrolled position of your view.
| |||||||||||
Set the scrolled position of your view.
| |||||||||||
Convenience method to scroll to a certain position.
| |||||||||||
Sets the accessibility delegate compatibility implementation used by RecyclerView.
| |||||||||||
Set a new adapter to provide child views on demand.
| |||||||||||
Sets whether this ViewGroup will clip its children to its padding, if
padding is present.
| |||||||||||
RecyclerView can perform several optimizations if it can know in advance that changes in
adapter content cannot change the size of the RecyclerView itself.
| |||||||||||
Sets the
RecyclerView.ItemAnimator that will handle animations involving changes
to the items in this RecyclerView.
| |||||||||||
Set the number of offscreen views to retain before adding them to the potentially shared
recycled view pool .
| |||||||||||
Set the
RecyclerView.LayoutManager that this RecyclerView will use.
| |||||||||||
Set a listener that will be notified of any changes in scroll state or position.
| |||||||||||
Recycled view pools allow multiple RecyclerViews to share a common pool of scrap views.
| |||||||||||
Register a listener that will be notified whenever a child view is recycled.
| |||||||||||
Configure the scrolling touch slop for a specific use case.
| |||||||||||
Sets a new
RecyclerView.ViewCacheExtension to be used by the Recycler.
| |||||||||||
Animate a scroll by the given amount of pixels along either axis.
| |||||||||||
Starts a smooth scroll to an adapter position.
| |||||||||||
Stop any current scroll in progress, such as one started by
smoothScrollBy(int, int) , fling(int, int) or a touch-initiated fling.
| |||||||||||
Swaps the current adapter with the provided one.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns a set of default layout parameters.
| |||||||||||
Returns a safe set of layout parameters based on the supplied layout params.
| |||||||||||
This is called when the view is attached to a window.
| |||||||||||
This is called when the view is detached from a window.
| |||||||||||
Called from layout when this view should
assign a size and position to each of its children.
| |||||||||||
Measure the view and its content to determine the measured width and the measured height. | |||||||||||
Hook allowing a view to re-apply a representation of its internal state that had previously
been generated by
onSaveInstanceState() .
| |||||||||||
Hook allowing a view to generate a representation of its internal state
that can later be used to create a new instance with that same state.
| |||||||||||
This is called during layout when the size of this view has changed.
| |||||||||||
Finishes the removal of a detached view.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.view.ViewGroup
| |||||||||||
From class
android.view.View
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
android.view.ViewParent
| |||||||||||
From interface
android.view.ViewManager
| |||||||||||
From interface
android.graphics.drawable.Drawable.Callback
| |||||||||||
From interface
android.view.KeyEvent.Callback
| |||||||||||
From interface
android.view.accessibility.AccessibilityEventSource
| |||||||||||
From interface
android.support.v4.view.ScrollingView
|
The RecyclerView is currently being dragged by outside input such as user touch input.
The RecyclerView is not currently scrolling.
The RecyclerView is currently animating to a final position while not under outside control.
Constant for use with setScrollingTouchSlop(int)
. Indicates
that the RecyclerView should use the standard touch slop for smooth,
continuous scrolling.
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.
Adds any focusable views that are descendants of this view (possibly including this view if it is focusable itself) to views. This method adds all focusable views regardless if we are in touch mode or only views focusable in touch mode if we are in touch mode or only views that can take accessibility focus if accessibility is enabeld depending on the focusable mode paramater.
views | Focusable views found so far or null if all we are interested is the number of focusables. |
---|---|
direction | The direction of the focus. |
focusableMode | The type of focusables to be added. |
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.
decor | Decoration to add |
---|
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.
decor | Decoration to add |
---|---|
index | Position in the decoration chain to insert this decoration at. If this value is negative the decoration will be added at the end. |
Add an RecyclerView.OnItemTouchListener
to intercept touch events before they are dispatched
to child views or this view's standard scrolling behavior.
Client code may use listeners to implement item manipulation behavior. Once a listener
returns true from
onInterceptTouchEvent(RecyclerView, MotionEvent)
its
onTouchEvent(RecyclerView, MotionEvent)
method will be called
for each incoming MotionEvent until the end of the gesture.
listener | Listener to add |
---|
Compute the horizontal extent of the horizontal scrollbar's thumb within the horizontal range. This value is used to compute the length of the thumb within the scrollbar's track.
The range is expressed in arbitrary units that must be the same as the units used by
computeHorizontalScrollRange()
and computeHorizontalScrollOffset()
.
Default implementation returns 0.
If you want to support scroll bars, override
computeHorizontalScrollExtent(RecyclerView.State)
in your
LayoutManager.
Compute the horizontal offset of the horizontal scrollbar's thumb within the horizontal range. This value is used to compute the length of the thumb within the scrollbar's track.
The range is expressed in arbitrary units that must be the same as the units used by
computeHorizontalScrollRange()
and computeHorizontalScrollExtent()
.
Default implementation returns 0.
If you want to support scroll bars, override
computeHorizontalScrollOffset(RecyclerView.State)
in your
LayoutManager.
Compute the horizontal range that the horizontal scrollbar represents.
The range is expressed in arbitrary units that must be the same as the units used by
computeHorizontalScrollExtent()
and computeHorizontalScrollOffset()
.
Default implementation returns 0.
If you want to support scroll bars, override
computeHorizontalScrollRange(RecyclerView.State)
in your
LayoutManager.
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.
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.
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.
Manually render this view (and all of its children) to the given Canvas.
The view must have already done a full layout before this function is
called. When implementing a view, implement
onDraw(android.graphics.Canvas)
instead of overriding this method.
If you do need to override this method, call the superclass version.
c | The Canvas to which the View is rendered. |
---|
Find the topmost view under the given point.
x | Horizontal position in pixels to search |
---|---|
y | Vertical position in pixels to search |
Return the ViewHolder for the item in the given position of the data set. Unlike
findViewHolderForLayoutPosition(int)
this method takes into account any pending
adapter changes that may not be reflected to the layout yet. On the other hand, if
notifyDataSetChanged()
has been called but the new layout has not been
calculated yet, this method will return null
since the new positions of views
are unknown until the layout is calculated.
This method checks only the children of RecyclerView. If the item at the given
position
is not laid out, it will not create a new one.
position | The position of the item in the data set of the adapter |
---|
position
or null if there is no such item
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.
id | The id for the requested item |
---|
id
or null if there is no such item
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.
position | The position of the item in the data set of the adapter |
---|
position
or null if there is no such item
This method is deprecated.
use findViewHolderForLayoutPosition(int)
or
findViewHolderForAdapterPosition(int)
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.
velocityX | Initial horizontal velocity in pixels per second |
---|---|
velocityY | Initial vertical velocity in pixels per second |
Find the nearest view in the specified direction that wants to take focus.
focused | The view that currently has focus |
---|---|
direction | One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT, or 0 for not applicable. |
Returns a new set of layout parameters based on the supplied attributes set.
attrs | the attributes to build the layout parameters from |
---|
ViewGroup.LayoutParams
or one
of its descendants
Retrieves the previously set adapter or null if no adapter is set.
Return the adapter position that the given child view corresponds to.
child | Child View to query |
---|
NO_POSITION
Return the stable item id that the given child view corresponds to.
child | Child View to query |
---|
NO_ID
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.
child | Child View to query |
---|
NO_POSITION
if
the View is representing a removed item.
Retrieve the RecyclerView.ViewHolder
for the given child view.
child | Child of this RecyclerView to query for its ViewHolder |
---|
Returns the accessibility delegate compatibility implementation used by the RecyclerView.
Gets the current ItemAnimator for this RecyclerView. A null return value
indicates that there is no animator and that item changes will happen without
any animations. By default, RecyclerView instantiates and
uses an instance of DefaultItemAnimator
.
Return the RecyclerView.LayoutManager
currently responsible for
layout policy for this RecyclerView.
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.
Return the current scrolling state of the RecyclerView.
Invalidates all ItemDecorations. If RecyclerView has item decorations, calling this method
will trigger a requestLayout()
call.
Offset the bounds of all child views by dx
pixels.
Useful for implementing simple scrolling in LayoutManagers
.
dx | Horizontal pixel offset to apply to the bounds of all child views |
---|
Offset the bounds of all child views by dy
pixels.
Useful for implementing simple scrolling in LayoutManagers
.
dy | Vertical pixel offset to apply to the bounds of all child views |
---|
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.
child | Child view that is now attached to this RecyclerView and its associated window |
---|
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.
child | Child view that is now detached from this RecyclerView and its associated window |
---|
Implement this to do your drawing.
c | the canvas on which the background will be drawn |
---|
Implement this method to handle generic motion events.
Generic motion events describe joystick movements, mouse hovers, track pad
touches, scroll wheel movements and other input events. The
source
of the motion event specifies
the class of input that was received. Implementations of this method
must examine the bits in the source before processing the event.
The following code example shows how this is done.
Generic motion events with source class SOURCE_CLASS_POINTER
are delivered to the view under the pointer. All other generic motion events are
delivered to the focused view.
public boolean onGenericMotionEvent(MotionEvent event) { if (event.isFromSource(InputDevice.SOURCE_CLASS_JOYSTICK)) { if (event.getAction() == MotionEvent.ACTION_MOVE) { // process the joystick movement... return true; } } if (event.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) { switch (event.getAction()) { case MotionEvent.ACTION_HOVER_MOVE: // process the mouse hover movement... return true; case MotionEvent.ACTION_SCROLL: // process the scroll wheel movement... return true; } } return super.onGenericMotionEvent(event); }
event | The generic motion event being processed. |
---|
Implement this method to intercept all touch screen motion events. This allows you to watch events as they are dispatched to your children, and take ownership of the current gesture at any point.
Using this function takes some care, as it has a fairly complicated
interaction with View.onTouchEvent(MotionEvent)
, and using it requires implementing
that method as well as this one in the correct way. Events will be
received in the following order:
ACTION_CANCEL
, and all further
events will be delivered to your onTouchEvent() method and no longer
appear here.
e | The motion event being dispatched down the hierarchy. |
---|
Implement this method to handle touch screen motion events.
If this method is used to detect click actions, it is recommended that
the actions be performed by implementing and calling
performClick()
. This will ensure consistent system behavior,
including:
ACTION_CLICK
when
accessibility features are enabled
e | The motion event. |
---|
Remove an RecyclerView.ItemDecoration
from this RecyclerView.
The given decoration will no longer impact the measurement and drawing of item views.
decor | Decoration to remove |
---|
Remove an RecyclerView.OnItemTouchListener
. It will no longer be able to intercept touch events.
listener | Listener to remove |
---|
Called when a child of this parent wants focus
child | The child of this ViewParent that wants focus. This view will contain the focused view. It is not necessarily the view that actually has focus. |
---|---|
focused | The view that is a descendant of child that actually has focus |
Called when a child of this group wants a particular rectangle to be
positioned onto the screen. ViewGroup
s overriding this can trust
that:
ViewGroup
s overriding this should uphold the contract:
child | The direct child making the request. |
---|---|
rect | The rectangle in the child's coordinates the child wishes to be on the screen. |
immediate | True to forbid animated or delayed scrolling, false otherwise |
Call this when something has changed which has invalidated the
layout of this view. This will schedule a layout pass of the view
tree. This should not be called while the view hierarchy is currently in a layout
pass (isInLayout()
. If layout is happening, the request may be honored at the
end of the current layout pass (and then layout will run again) or after the current
frame is drawn and the next layout occurs.
Subclasses which override this method should call the superclass method to handle possible request-during-layout errors correctly.
Move the scrolled position of your view. This will cause a call to
onScrollChanged(int, int, int, int)
and the view will be
invalidated.
x | the amount of pixels to scroll by horizontally |
---|---|
y | the amount of pixels to scroll by vertically |
Set the scrolled position of your view. This will cause a call to
onScrollChanged(int, int, int, int)
and the view will be
invalidated.
x | the x position to scroll to |
---|---|
y | the y position to scroll to |
Convenience method to scroll to a certain position.
RecyclerView does not implement scrolling logic, rather forwards the call to
scrollToPosition(int)
position | Scroll to this adapter position |
---|
Sets the accessibility delegate compatibility implementation used by RecyclerView.
accessibilityDelegate | The accessibility delegate to be used by RecyclerView. |
---|
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.
adapter | The new adapter to set, or null to set no adapter. |
---|
Sets whether this ViewGroup will clip its children to its padding, if padding is present.
By default, children are clipped to the padding of their parent Viewgroup. This clipping behavior is only enabled if padding is non-zero.
clipToPadding | true to clip children to the padding of the group, false otherwise |
---|
RecyclerView can perform several optimizations if it can know in advance that changes in adapter content cannot change the size of the RecyclerView itself. If your use of RecyclerView falls into this category, set this to true.
hasFixedSize | true if adapter changes cannot affect the size of the RecyclerView. |
---|
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
.
animator | The ItemAnimator being set. If null, no animations will occur when changes occur to the items in this RecyclerView. |
---|
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.
size | Number of views to cache offscreen before returning them to the general recycled view pool |
---|
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.
layout | LayoutManager to use |
---|
Set a listener that will be notified of any changes in scroll state or position.
listener | Listener to set or null to clear |
---|
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
.
pool | Pool to set. If this parameter is null a new pool will be created and used. |
---|
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.
listener | Listener to register, or null to clear |
---|
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
.
slopConstant | One of the TOUCH_SLOP_ constants representing
the intended usage of this RecyclerView
|
---|
Sets a new RecyclerView.ViewCacheExtension
to be used by the Recycler.
extension | ViewCacheExtension to be used or null if you want to clear the existing one. |
---|
Animate a scroll by the given amount of pixels along either axis.
dx | Pixels to scroll horizontally |
---|---|
dy | Pixels to scroll vertically |
Starts a smooth scroll to an adapter position.
To support smooth scrolling, you must override
smoothScrollToPosition(RecyclerView, State, int)
and create a
RecyclerView.SmoothScroller
.
RecyclerView.LayoutManager
is responsible for creating the actual scroll action. If you want to
provide a custom smooth scroll logic, override
smoothScrollToPosition(RecyclerView, State, int)
in your
LayoutManager.
position | The adapter position to scroll to |
---|
Stop any current scroll in progress, such as one started by
smoothScrollBy(int, int)
, fling(int, int)
or a touch-initiated fling.
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.
adapter | The new adapter to set, or null to set no adapter. |
---|---|
removeAndRecycleExistingViews | If set to true, RecyclerView will recycle all existing Views. If adapters have stable ids and/or you want to animate the disappearing views, you may prefer to set this to false. |
Returns a set of default layout parameters. These parameters are requested
when the View passed to addView(View)
has no layout parameters
already set. If null is returned, an exception is thrown from addView.
Returns a safe set of layout parameters based on the supplied layout params.
When a ViewGroup is passed a View whose layout params do not pass the test of
checkLayoutParams(android.view.ViewGroup.LayoutParams)
, this method
is invoked. This method should return a new set of layout params suitable for
this ViewGroup, possibly by copying the appropriate attributes from the
specified set of layout params.
p | The layout parameters to convert into a suitable set of layout parameters for this ViewGroup. |
---|
ViewGroup.LayoutParams
or one
of its descendants
This is called when the view is attached to a window. At this point it
has a Surface and will start drawing. Note that this function is
guaranteed to be called before onDraw(android.graphics.Canvas)
,
however it may be called any time before the first onDraw -- including
before or after onMeasure(int, int)
.
This is called when the view is detached from a window. At this point it no longer has a surface for drawing.
Called from layout when this view should assign a size and position to each of its children. Derived classes with children should override this method and call layout on each of their children.
changed | This is a new size or position for this view |
---|---|
l | Left position, relative to parent |
t | Top position, relative to parent |
r | Right position, relative to parent |
b | Bottom position, relative to parent |
Measure the view and its content to determine the measured width and the
measured height. This method is invoked by measure(int, int)
and
should be overriden by subclasses to provide accurate and efficient
measurement of their contents.
CONTRACT: When overriding this method, you
must call setMeasuredDimension(int, int)
to store the
measured width and height of this view. Failure to do so will trigger an
IllegalStateException
, thrown by
measure(int, int)
. Calling the superclass'
onMeasure(int, int)
is a valid use.
The base class implementation of measure defaults to the background size,
unless a larger size is allowed by the MeasureSpec. Subclasses should
override onMeasure(int, int)
to provide better measurements of
their content.
If this method is overridden, it is the subclass's responsibility to make
sure the measured height and width are at least the view's minimum height
and width (getSuggestedMinimumHeight()
and
getSuggestedMinimumWidth()
).
widthSpec | horizontal space requirements as imposed by the parent.
The requirements are encoded with
View.MeasureSpec . |
---|---|
heightSpec | vertical space requirements as imposed by the parent.
The requirements are encoded with
View.MeasureSpec . |
Hook allowing a view to re-apply a representation of its internal state that had previously
been generated by onSaveInstanceState()
. This function will never be called with a
null state.
state | The frozen state that had previously been returned by
onSaveInstanceState() . |
---|
Hook allowing a view to generate a representation of its internal state that can later be used to create a new instance with that same state. This state should only contain information that is not persistent or can not be reconstructed later. For example, you will never store your current position on screen because that will be computed again when a new instance of the view is placed in its view hierarchy.
Some examples of things you may store here: the current cursor position in a text view (but usually not the text itself since that is stored in a content provider or other persistent storage), the currently selected item in a list view.
This is called during layout when the size of this view has changed. If you were just added to the view hierarchy, you're called with the old values of 0.
w | Current width of this view. |
---|---|
h | Current height of this view. |
oldw | Old width of this view. |
oldh | Old height of this view. |
Finishes the removal of a detached view. This method will dispatch the detached from window event and notify the hierarchy change listener.
This method is intended to be lightweight and makes no assumptions about whether the
parent or child should be redrawn. Proper use of this method will include also making
any appropriate requestLayout()
or invalidate()
calls.
For example, callers can post
a Runnable
which performs a requestLayout()
on the next frame, after all detach/remove
calls are finished, causing layout to be run prior to redrawing the view hierarchy.
child | the child to be definitely removed from the view hierarchy |
---|---|
animate | if true and the view has an animation, the view is placed in the disappearing views list, otherwise, it is detached from the window |