ViewPager
public class ViewPager extends ViewGroup
LeanbackViewPager |
A viewpager with touch and key event handling disabled by default. |
Layout manager that allows the user to flip left and right through pages of data. You supply an implementation of a PagerAdapter to generate the pages that the view shows.
ViewPager is most often used in conjunction with android.app.Fragment, which is a convenient way to supply and manage the lifecycle of each page. There are standard adapters implemented for using fragments with the ViewPager, which cover the most common use cases. These are androidx.fragment.app.FragmentPagerAdapter and androidx.fragment.app.FragmentStatePagerAdapter; each of these classes have simple code showing how to build a full user interface with them.
Views which are annotated with the DecorView annotation are treated as part of the view pagers 'decor'. Each decor view's position can be controlled via its android:layout_gravity attribute. For example:
<androidx.viewpager.widget.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.viewpager.widget.PagerTitleStrip
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top" />
</androidx.viewpager.widget.ViewPager>For more information about how to use ViewPager, read Creating Swipe Views with Tabs.
You can find examples of using ViewPager in the API 4+ Support Demos and API 13+ Support Demos sample code.
Summary
Nested types |
|---|
@Retention(value = RetentionPolicy.RUNTIME)Annotation which allows marking of views to be decoration views when added to a view pager. |
public class ViewPager.LayoutParams extends ViewGroup.LayoutParamsLayout parameters that should be supplied for views added to a ViewPager. |
public interface ViewPager.OnAdapterChangeListenerCallback interface for responding to adapter changes. |
public interface ViewPager.OnPageChangeListenerCallback interface for responding to changing state of the selected page. |
public interface ViewPager.PageTransformerA PageTransformer is invoked whenever a visible/attached page is scrolled. |
public class ViewPager.SavedState extends AbsSavedStateThis is the persistent state that is saved by ViewPager. |
public class ViewPager.SimpleOnPageChangeListener implements ViewPager.OnPageChangeListenerSimple implementation of the |
Constants |
|
|---|---|
static final int |
Indicates that the pager is currently being dragged by the user. |
static final int |
Indicates that the pager is in an idle, settled state. |
static final int |
Indicates that the pager is in the process of settling to a final position. |
Public constructors |
|---|
ViewPager(@NonNull Context context, @Nullable AttributeSet attrs) |
Public methods |
|
|---|---|
void |
addFocusables(ArrayList<View> views, int direction, int focusableMode)We only want the current page that is being shown to be focusable. |
void |
Add a listener that will be invoked whenever the adapter for this ViewPager changes. |
void |
Add a listener that will be invoked whenever the page changes or is incrementally scrolled. |
void |
addTouchables(ArrayList<View> views)We only want the current page that is being shown to be touchable. |
void |
addView(View child, int index, ViewGroup.LayoutParams params) |
boolean |
arrowScroll(int direction)Handle scrolling in response to a left or right arrow click. |
boolean |
Start a fake drag of the pager. |
boolean |
canScrollHorizontally(int direction)Check if this ViewPager can be scrolled horizontally in a certain direction. |
void |
Remove all listeners that are notified of any changes in scroll state or position. |
void |
|
boolean |
dispatchKeyEvent(KeyEvent event) |
boolean |
|
void |
|
void |
End a fake drag of the pager. |
boolean |
executeKeyEvent(@NonNull KeyEvent event)You can call this function yourself to have the scroll view perform scrolling from a key event, just as if the event had been dispatched to it by the view hierarchy. |
void |
fakeDragBy(float xOffset)Fake drag by an offset in pixels. |
ViewGroup.LayoutParams |
generateLayoutParams(AttributeSet attrs) |
@Nullable PagerAdapter |
Retrieve the current adapter supplying pages. |
int |
|
int |
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 |
Return the margin between pages. |
boolean |
|
boolean |
Returns true if a fake drag is in progress. |
boolean |
|
void |
onRestoreInstanceState(Parcelable state) |
@NonNull Parcelable |
|
boolean |
|
void |
Remove a listener that was previously added via |
void |
Remove a listener that was previously added via |
void |
removeView(View view) |
void |
setAdapter(@Nullable PagerAdapter adapter)Set a PagerAdapter that will supply views for this pager as needed. |
void |
setCurrentItem(int item)Set the currently selected page. |
void |
setCurrentItem(int item, boolean smoothScroll)Set the currently selected page. |
void |
setDragInGutterEnabled(boolean enabled)Set whether ViewPager should consume drag events if they are within the gutter (left and right edges) of the ViewPager. |
void |
setOffscreenPageLimit(int limit)Set the number of pages that should be retained to either side of the current page in the view hierarchy in an idle state. |
void |
This method is deprecated. Use |
void |
setPageMargin(int marginPixels)Set the margin between pages. |
void |
Set a drawable that will be used to fill the margin between pages. |
void |
setPageMarginDrawable(@DrawableRes int resId)Set a drawable that will be used to fill the margin between pages. |
void |
setPageTransformer(Sets a |
void |
setPageTransformer(Sets a |
Protected methods |
|
|---|---|
boolean |
Tests scrollability within child views of v given a delta of dx. |
boolean |
|
void |
|
ViewGroup.LayoutParams |
|
ViewGroup.LayoutParams |
|
int |
getChildDrawingOrder(int childCount, int i) |
void |
|
void |
|
void |
|
void |
onLayout(boolean changed, int l, int t, int r, int b) |
void |
onMeasure(int widthMeasureSpec, int heightMeasureSpec) |
void |
@CallSuperThis method will be invoked when the current page is scrolled, either as part of a programmatically initiated smooth scroll or a user initiated touch scroll. |
boolean |
onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect)We only want the current page that is being shown to be focusable. |
void |
onSizeChanged(int w, int h, int oldw, int oldh) |
boolean |
verifyDrawable(@NonNull Drawable who) |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Inherited methods |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Constants
SCROLL_STATE_DRAGGING
public static final int SCROLL_STATE_DRAGGING = 1
Indicates that the pager is currently being dragged by the user.
SCROLL_STATE_IDLE
public static final int SCROLL_STATE_IDLE = 0
Indicates that the pager is in an idle, settled state. The current page is fully in view and no animation is in progress.
SCROLL_STATE_SETTLING
public static final int SCROLL_STATE_SETTLING = 2
Indicates that the pager is in the process of settling to a final position.
Public constructors
Public methods
addFocusables
public void addFocusables(ArrayList<View> views, int direction, int focusableMode)
We only want the current page that is being shown to be focusable.
addOnAdapterChangeListener
public void addOnAdapterChangeListener(
@NonNull ViewPager.OnAdapterChangeListener listener
)
Add a listener that will be invoked whenever the adapter for this ViewPager changes.
| Parameters | |
|---|---|
@NonNull ViewPager.OnAdapterChangeListener listener |
listener to add |
addOnPageChangeListener
public void addOnPageChangeListener(
@NonNull ViewPager.OnPageChangeListener listener
)
Add a listener that will be invoked whenever the page changes or is incrementally scrolled. See OnPageChangeListener.
Components that add a listener should take care to remove it when finished. Other components that take ownership of a view may call clearOnPageChangeListeners to remove all attached listeners.
| Parameters | |
|---|---|
@NonNull ViewPager.OnPageChangeListener listener |
listener to add |
addTouchables
public void addTouchables(ArrayList<View> views)
We only want the current page that is being shown to be touchable.
arrowScroll
public boolean arrowScroll(int direction)
Handle scrolling in response to a left or right arrow click.
| Parameters | |
|---|---|
int direction |
The direction corresponding to the arrow key that was pressed. It should be either |
| Returns | |
|---|---|
boolean |
Whether the scrolling was handled successfully. |
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 ViewPager with the touch scrolling of another view, while still letting the ViewPager control the snapping motion and fling behavior. (e.g. parallax-scrolling tabs.) Call fakeDragBy to simulate the actual drag motion. Call endFakeDrag to complete the fake drag and fling as necessary.
During a fake drag the ViewPager will ignore all touch events. If a real 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. |
| See also | |
|---|---|
fakeDragBy |
|
endFakeDrag |
canScrollHorizontally
public boolean canScrollHorizontally(int direction)
Check if this ViewPager can be scrolled horizontally in a certain direction.
| Parameters | |
|---|---|
int direction |
Negative to check scrolling left, positive to check scrolling right. |
| Returns | |
|---|---|
boolean |
Whether this ViewPager can be scrolled in the specified direction. It will always return false if the specified direction is 0. |
clearOnPageChangeListeners
public void clearOnPageChangeListeners()
Remove all listeners that are notified of any changes in scroll state or position.
dispatchPopulateAccessibilityEvent
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event)
endFakeDrag
public void endFakeDrag()
End a fake drag of the pager.
| See also | |
|---|---|
beginFakeDrag |
|
fakeDragBy |
executeKeyEvent
public boolean executeKeyEvent(@NonNull KeyEvent event)
You can call this function yourself to have the scroll view perform scrolling from a key event, just as if the event had been dispatched to it by the view hierarchy.
| Returns | |
|---|---|
boolean |
Return true if the event was handled, else false. |
fakeDragBy
public void fakeDragBy(float xOffset)
Fake drag by an offset in pixels. You must have called beginFakeDrag first.
| Parameters | |
|---|---|
float xOffset |
Offset in pixels to drag by. |
| See also | |
|---|---|
beginFakeDrag |
|
endFakeDrag |
getAdapter
public @Nullable PagerAdapter getAdapter()
Retrieve the current adapter supplying pages.
| Returns | |
|---|---|
@Nullable PagerAdapter |
The currently registered PagerAdapter |
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 1.
| Returns | |
|---|---|
int |
How many pages will be kept offscreen on either side |
| See also | |
|---|---|
setOffscreenPageLimit |
getPageMargin
public int getPageMargin()
Return the margin between pages.
| Returns | |
|---|---|
int |
The size of the margin in pixels |
isDragInGutterEnabled
public boolean isDragInGutterEnabled()
| Returns | |
|---|---|
boolean |
Whether dragging in the gutter (left and right edges) of the ViewPager is enabled. |
isFakeDragging
public boolean isFakeDragging()
Returns true if a fake drag is in progress.
| Returns | |
|---|---|
boolean |
true if currently in a fake drag, false otherwise. |
| See also | |
|---|---|
beginFakeDrag |
|
fakeDragBy |
|
endFakeDrag |
removeOnAdapterChangeListener
public void removeOnAdapterChangeListener(
@NonNull ViewPager.OnAdapterChangeListener listener
)
Remove a listener that was previously added via addOnAdapterChangeListener.
| Parameters | |
|---|---|
@NonNull ViewPager.OnAdapterChangeListener listener |
listener to remove |
removeOnPageChangeListener
public void removeOnPageChangeListener(
@NonNull ViewPager.OnPageChangeListener listener
)
Remove a listener that was previously added via addOnPageChangeListener.
| Parameters | |
|---|---|
@NonNull ViewPager.OnPageChangeListener listener |
listener to remove |
setAdapter
public void setAdapter(@Nullable PagerAdapter adapter)
Set a PagerAdapter that will supply views for this pager as needed.
| Parameters | |
|---|---|
@Nullable PagerAdapter adapter |
Adapter to use |
setCurrentItem
public void setCurrentItem(int item)
Set the currently selected page. If the ViewPager has already been through its first layout with its current adapter there will be a smooth animated transition between the current item and the specified item.
| Parameters | |
|---|---|
int item |
Item index to select |
setCurrentItem
public void setCurrentItem(int item, boolean smoothScroll)
Set the currently selected page.
| Parameters | |
|---|---|
int item |
Item index to select |
boolean smoothScroll |
True to smoothly scroll to the new item, false to transition immediately |
setDragInGutterEnabled
public void setDragInGutterEnabled(boolean enabled)
Set whether ViewPager should consume drag events if they are within the gutter (left and right edges) of the ViewPager. The default value false.
| Parameters | |
|---|---|
boolean enabled |
true if ViewPager should allow drag in gutter, false otherwise |
setOffscreenPageLimit
public void setOffscreenPageLimit(int limit)
Set the number of pages that should be retained to either side of the current page in the view hierarchy in an idle state. Pages beyond this limit will be recreated from the adapter when needed.
This is offered as an optimization. If you know in advance the number of pages you will need to support or have lazy-loading mechanisms in place on your pages, tweaking this setting can have benefits in perceived smoothness of paging animations and interaction. If you have a small number of pages (3-4) that you can keep active all at once, less time will be spent in layout for newly created view subtrees as the user pages back and forth.
You should keep this limit low, especially if your pages have complex layouts. This setting defaults to 1.
| Parameters | |
|---|---|
int limit |
How many pages will be kept offscreen in an idle state. |
public voidsetOnPageChangeListener(ViewPager.OnPageChangeListener listener)
Set a listener that will be invoked whenever the page changes or is incrementally scrolled. See OnPageChangeListener.
| Parameters | |
|---|---|
ViewPager.OnPageChangeListener listener |
Listener to set |
setPageMargin
public void setPageMargin(int marginPixels)
Set the margin between pages.
| Parameters | |
|---|---|
int marginPixels |
Distance between adjacent pages in pixels |
setPageMarginDrawable
public void setPageMarginDrawable(@Nullable Drawable d)
Set a drawable that will be used to fill the margin between pages.
setPageMarginDrawable
public void setPageMarginDrawable(@DrawableRes int resId)
Set a drawable that will be used to fill the margin between pages.
| Parameters | |
|---|---|
@DrawableRes int resId |
Resource ID of a drawable to display between pages |
setPageTransformer
public void setPageTransformer(
boolean reverseDrawingOrder,
@Nullable ViewPager.PageTransformer transformer
)
Sets a PageTransformer that will be called for each attached page whenever the scroll position is changed. This allows the application to apply custom property transformations to each page, overriding the default sliding behavior.
Note: By default, calling this method will cause contained pages to use LAYER_TYPE_HARDWARE. This layer type allows custom alpha transformations, but it will cause issues if any of your pages contain a android.view.SurfaceView and you have not called setZOrderOnTop to put that android.view.SurfaceView above your app content. To disable this behavior, call setPageTransformer and pass LAYER_TYPE_NONE for pageLayerType.
| Parameters | |
|---|---|
boolean reverseDrawingOrder |
true if the supplied PageTransformer requires page views to be drawn from last to first instead of first to last. |
@Nullable ViewPager.PageTransformer transformer |
PageTransformer that will modify each page's animation properties |
setPageTransformer
public void setPageTransformer(
boolean reverseDrawingOrder,
@Nullable ViewPager.PageTransformer transformer,
int pageLayerType
)
Sets a PageTransformer that will be called for each attached page whenever the scroll position is changed. This allows the application to apply custom property transformations to each page, overriding the default sliding behavior.
| Parameters | |
|---|---|
boolean reverseDrawingOrder |
true if the supplied PageTransformer requires page views to be drawn from last to first instead of first to last. |
@Nullable ViewPager.PageTransformer transformer |
PageTransformer that will modify each page's animation properties |
int pageLayerType |
View layer type that should be used for ViewPager pages. It should be either |
Protected methods
canScroll
protected boolean canScroll(@NonNull View v, boolean checkV, int dx, int x, int y)
Tests scrollability within child views of v given a delta of dx.
| Parameters | |
|---|---|
@NonNull View v |
View to test for horizontal scrollability |
boolean checkV |
Whether the view v passed should itself be checked for scrollability (true), or just its children (false). |
int dx |
Delta scrolled in pixels |
int x |
X coordinate of the active touch point |
int y |
Y coordinate of the active touch point |
| Returns | |
|---|---|
boolean |
true if child views of v can be scrolled by delta of dx. |
generateLayoutParams
protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p)
onPageScrolled
@CallSuper
protected void onPageScrolled(int position, float offset, int offsetPixels)
This method will be invoked when the current page is scrolled, either as part of a programmatically initiated smooth scroll or a user initiated touch scroll. If you override this method you must call through to the superclass implementation (e.g. super.onPageScrolled(position, offset, offsetPixels)) before onPageScrolled returns.
| Parameters | |
|---|---|
int position |
Position index of the first page currently being displayed. Page position+1 will be visible if positionOffset is nonzero. |
float offset |
Value from [0, 1) indicating the offset from the page at position. |
int offsetPixels |
Value in pixels indicating the offset from position. |
onRequestFocusInDescendants
protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect)
We only want the current page that is being shown to be focusable.