ViewPager2
public
final
class
ViewPager2
extends ViewGroup
java.lang.Object | |||
↳ | android.view.View | ||
↳ | android.view.ViewGroup | ||
↳ | androidx.viewpager2.widget.ViewPager2 |
ViewPager2 replaces ViewPager
, addressing most of its
predecessor’s pain-points, including right-to-left layout support, vertical orientation,
modifiable Fragment collections, etc.
See also:
Summary
Nested classes | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
class |
ViewPager2.OnPageChangeCallback
Callback interface for responding to changing state of the selected page. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
interface |
ViewPager2.PageTransformer
A PageTransformer is invoked whenever a visible/attached page is scrolled. |
Constants | |
---|---|
int |
OFFSCREEN_PAGE_LIMIT_DEFAULT
Value to indicate that the default caching mechanism of RecyclerView should be used instead of explicitly prefetch and retain pages to either side of the current page. |
int |
ORIENTATION_HORIZONTAL
|
int |
ORIENTATION_VERTICAL
|
int |
SCROLL_STATE_DRAGGING
Indicates that the ViewPager2 is currently being dragged by the user, or programmatically via fake drag functionality. |
int |
SCROLL_STATE_IDLE
Indicates that the ViewPager2 is in an idle, settled state. |
int |
SCROLL_STATE_SETTLING
Indicates that the ViewPager2 is in the process of settling to a final position. |
Inherited constants | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.view.ViewGroup
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
From class
android.view.View
|
Inherited fields | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.view.View
|
Public constructors | |
---|---|
ViewPager2(Context context)
|
|
ViewPager2(Context context, AttributeSet attrs)
|
|
ViewPager2(Context context, AttributeSet attrs, int defStyleAttr)
|
|
ViewPager2(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
|
Public methods | |
---|---|
void
|
addItemDecoration(RecyclerView.ItemDecoration decor)
Add an |
void
|
addItemDecoration(RecyclerView.ItemDecoration decor, int index)
Add an |
boolean
|
beginFakeDrag()
Start a fake drag of the pager. |
boolean
|
canScrollHorizontally(int direction)
|
boolean
|
canScrollVertically(int direction)
|
boolean
|
endFakeDrag()
End a fake drag of the pager. |
boolean
|
fakeDragBy(float offsetPxFloat)
Fake drag by an offset in pixels. |
CharSequence
|
getAccessibilityClassName()
|
Adapter
|
getAdapter()
|
int
|
getCurrentItem()
Returns the currently selected page. |
RecyclerView.ItemDecoration
|
getItemDecorationAt(int index)
Returns an |
int
|
getItemDecorationCount()
Returns the number of |
int
|
getOffscreenPageLimit()
Returns the number of pages that will be retained to either side of the current page in the view hierarchy in an idle state. |
int
|
getOrientation()
|
int
|
getScrollState()
Returns the current scroll state of the ViewPager2. |
void
|
invalidateItemDecorations()
Invalidates all ItemDecorations. |
boolean
|
isFakeDragging()
Returns |
boolean
|
isUserInputEnabled()
Returns if user initiated scrolling between pages is enabled. |
void
|
onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)
|
void
|
onViewAdded(View child)
|
boolean
|
performAccessibilityAction(int action, Bundle arguments)
|
void
|
registerOnPageChangeCallback(ViewPager2.OnPageChangeCallback callback)
Add a callback that will be invoked whenever the page changes or is incrementally scrolled. |
void
|
removeItemDecoration(RecyclerView.ItemDecoration decor)
Remove an |
void
|
removeItemDecorationAt(int index)
Removes the |
void
|
requestTransform()
Trigger a call to the registered |
void
|
setAdapter(Adapter adapter)
Set a new adapter to provide page views on demand. |
void
|
setCurrentItem(int item)
Set the currently selected page. |
void
|
setCurrentItem(int item, boolean smoothScroll)
Set the currently selected page. |
void
|
setLayoutDirection(int layoutDirection)
|
void
|
setOffscreenPageLimit(int limit)
Set the number of pages that should be retained to either side of the currently visible page(s). |
void
|
setOrientation(int orientation)
Sets the orientation of the ViewPager2. |
void
|
setPageTransformer(ViewPager2.PageTransformer transformer)
Sets a |
void
|
setUserInputEnabled(boolean enabled)
Enable or disable user initiated scrolling. |
void
|
unregisterOnPageChangeCallback(ViewPager2.OnPageChangeCallback callback)
Remove a callback that was previously added via
|
Protected methods | |
---|---|
void
|
dispatchRestoreInstanceState(SparseArray<Parcelable> container)
|
void
|
onLayout(boolean changed, int l, int t, int r, int b)
|
void
|
onMeasure(int widthMeasureSpec, int heightMeasureSpec)
|
void
|
onRestoreInstanceState(Parcelable state)
|
Parcelable
|
onSaveInstanceState()
|
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
|
Constants
OFFSCREEN_PAGE_LIMIT_DEFAULT
public static final int OFFSCREEN_PAGE_LIMIT_DEFAULT
Value to indicate that the default caching mechanism of RecyclerView should be used instead of explicitly prefetch and retain pages to either side of the current page.
See also:
Constant Value: -1 (0xffffffff)
ORIENTATION_HORIZONTAL
public static final int ORIENTATION_HORIZONTAL
Constant Value: 0 (0x00000000)
ORIENTATION_VERTICAL
public static final int ORIENTATION_VERTICAL
Constant Value: 1 (0x00000001)
SCROLL_STATE_DRAGGING
public static final int SCROLL_STATE_DRAGGING
Indicates that the ViewPager2 is currently being dragged by the user, or programmatically via fake drag functionality.
Constant Value: 1 (0x00000001)
SCROLL_STATE_IDLE
public static final int SCROLL_STATE_IDLE
Indicates that the ViewPager2 is in an idle, settled state. The current page is fully in view and no animation is in progress.
Constant Value: 0 (0x00000000)
SCROLL_STATE_SETTLING
public static final int SCROLL_STATE_SETTLING
Indicates that the ViewPager2 is in the process of settling to a final position.
Constant Value: 2 (0x00000002)
Public constructors
ViewPager2
public ViewPager2 (Context context, AttributeSet attrs)
Parameters | |
---|---|
context |
Context |
attrs |
AttributeSet |
ViewPager2
public ViewPager2 (Context context, AttributeSet attrs, int defStyleAttr)
Parameters | |
---|---|
context |
Context |
attrs |
AttributeSet |
defStyleAttr |
int |
ViewPager2
public ViewPager2 (Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
Parameters | |
---|---|
context |
Context |
attrs |
AttributeSet |
defStyleAttr |
int |
defStyleRes |
int |
Public methods
addItemDecoration
public void addItemDecoration (RecyclerView.ItemDecoration decor)
Add an RecyclerView.ItemDecoration
to this ViewPager2. 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
public void addItemDecoration (RecyclerView.ItemDecoration decor, int index)
Add an RecyclerView.ItemDecoration
to this ViewPager2. 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. |
Throws | |
---|---|
IndexOutOfBoundsException |
on indexes larger than getItemDecorationCount()
|
beginFakeDrag
public boolean beginFakeDrag ()
Start a fake drag of the pager.
A fake drag can be useful if you want to synchronize the motion of the ViewPager2 with the
touch scrolling of another view, while still letting the ViewPager2 control the snapping
motion and fling behavior. (e.g. parallax-scrolling tabs.) Call fakeDragBy(float)
to
simulate the actual drag motion. Call endFakeDrag()
to complete the fake drag and
fling as necessary.
A fake drag can be interrupted by a real drag. From that point on, all calls to fakeDragBy
and endFakeDrag
will be ignored until the next fake drag is started by
calling beginFakeDrag
. If you need the ViewPager2 to ignore touch events and other
user input during a fake drag, use setUserInputEnabled(boolean)
. If a real or fake
drag is already in progress, this method will return false
.
Returns | |
---|---|
boolean |
true if the fake drag began successfully, false if it could not be
started |
canScrollHorizontally
public boolean canScrollHorizontally (int direction)
Parameters | |
---|---|
direction |
int |
Returns | |
---|---|
boolean |
canScrollVertically
public boolean canScrollVertically (int direction)
Parameters | |
---|---|
direction |
int |
Returns | |
---|---|
boolean |
endFakeDrag
public boolean endFakeDrag ()
End a fake drag of the pager.
Returns | |
---|---|
boolean |
true if the fake drag was ended. If false is returned, it means there
was no fake drag to end. |
fakeDragBy
public boolean fakeDragBy (float offsetPxFloat)
Fake drag by an offset in pixels. You must have called beginFakeDrag()
first. Drag
happens in the direction of the orientation. Positive offsets will drag to the previous page,
negative values to the next page, with one exception: if layout direction is set to RTL and
the ViewPager2's orientation is horizontal, then the behavior will be inverted. This matches
the deltas of touch events that would cause the same real drag.
If the pager is not in the fake dragging state anymore, it ignores this call and returns
false
.
Parameters | |
---|---|
offsetPxFloat |
float : Offset in pixels to drag by |
Returns | |
---|---|
boolean |
true if the fake drag was executed. If false is returned, it means
there was no fake drag to end. |
getAccessibilityClassName
public CharSequence getAccessibilityClassName ()
Returns | |
---|---|
CharSequence |
getCurrentItem
public int getCurrentItem ()
Returns the currently selected page. If no page can sensibly be selected because there is no adapter or the adapter is empty, returns 0.
Returns | |
---|---|
int |
Currently selected page |
getItemDecorationAt
public RecyclerView.ItemDecoration getItemDecorationAt (int index)
Returns an RecyclerView.ItemDecoration
previously added to this ViewPager2.
Parameters | |
---|---|
index |
int : The index position of the desired ItemDecoration. |
Returns | |
---|---|
RecyclerView.ItemDecoration |
the ItemDecoration at index position |
Throws | |
---|---|
IndexOutOfBoundsException |
on invalid index |
getItemDecorationCount
public int getItemDecorationCount ()
Returns the number of RecyclerView.ItemDecoration
currently added to this ViewPager2.
Returns | |
---|---|
int |
number of ItemDecorations currently added added to this ViewPager2. |
getOffscreenPageLimit
public int getOffscreenPageLimit ()
Returns the number of pages that will be retained to either side of the current page in the
view hierarchy in an idle state. Defaults to OFFSCREEN_PAGE_LIMIT_DEFAULT
.
Returns | |
---|---|
int |
How many pages will be kept offscreen on either side |
See also:
getOrientation
public int getOrientation ()
Returns | |
---|---|
int |
getScrollState
public int getScrollState ()
Returns the current scroll state of the ViewPager2. Returned value is one of can be one of
SCROLL_STATE_IDLE
, SCROLL_STATE_DRAGGING
or SCROLL_STATE_SETTLING
.
Returns | |
---|---|
int |
The scroll state that was last dispatched to ViewPager2.OnPageChangeCallback.onPageScrollStateChanged(int)
|
invalidateItemDecorations
public void invalidateItemDecorations ()
Invalidates all ItemDecorations. If ViewPager2 has item decorations, calling this method
will trigger a View.requestLayout()
call.
isFakeDragging
public boolean isFakeDragging ()
Returns true
if a fake drag is in progress.
Returns | |
---|---|
boolean |
true if currently in a fake drag, false otherwise. |
isUserInputEnabled
public boolean isUserInputEnabled ()
Returns if user initiated scrolling between pages is enabled. Enabled by default.
Returns | |
---|---|
boolean |
true if users can scroll the ViewPager2, false otherwise |
See also:
onInitializeAccessibilityNodeInfo
public void onInitializeAccessibilityNodeInfo (AccessibilityNodeInfo info)
Parameters | |
---|---|
info |
AccessibilityNodeInfo |
performAccessibilityAction
public boolean performAccessibilityAction (int action, Bundle arguments)
Parameters | |
---|---|
action |
int |
arguments |
Bundle |
Returns | |
---|---|
boolean |