-
- All Implemented Interfaces:
-
android.graphics.drawable.Drawable.Callback,android.view.KeyEvent.Callback,android.view.ViewManager,android.view.ViewParent,android.view.accessibility.AccessibilityEventSource
public class ViewPager extends ViewGroup
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 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
{@code android:layout_gravity}attribute. For example:<android.support.v4.view.ViewPager android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v4.view.PagerTitleStrip android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="top" /> </android.support.v4.view.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceViewPager.OnPageChangeListenerCallback interface for responding to changing state of the selected page.
public classViewPager.SimpleOnPageChangeListenerSimple implementation of the OnPageChangeListener interface with stubimplementations of each method. Extend this if you do not intend to overrideevery method of OnPageChangeListener.
public interfaceViewPager.PageTransformerA PageTransformer is invoked whenever a visible/attached page is scrolled.This offers an opportunity for the application to apply a custom transformationto the page views using animation properties.
As property animation is only supported as of Android 3.0 and forward,setting a PageTransformer on a ViewPager on earlier platform versions willbe ignored.
public interfaceViewPager.OnAdapterChangeListenerCallback interface for responding to adapter changes.
public @interfaceViewPager.DecorViewAnnotation which allows marking of views to be decoration views when added to a viewpager.
Views marked with this annotation can be added to the view pager with a layout resource.
You can also control whether a view is a decor view but setting isDecor on the child's layout params.
public classViewPager.SavedStateThis is the persistent state that is saved by ViewPager. Only neededif you are creating a sublass of ViewPager that must save its ownstate, in which case it should implement a subclass of this whichcontains that state.
public classViewPager.LayoutParamsLayout parameters that should be supplied for views added to aViewPager.
-
Field Summary
Fields Modifier and Type Field Description public final static intSCROLL_STATE_IDLEpublic final static intSCROLL_STATE_DRAGGINGpublic final static intSCROLL_STATE_SETTLING
-
Constructor Summary
Constructors Constructor Description ViewPager(Context context)ViewPager(Context context, AttributeSet attrs)
-
Method Summary
Modifier and Type Method Description voidsetAdapter(@Nullable() PagerAdapter adapter)Set a PagerAdapter that will supply views for this pager as needed. PagerAdaptergetAdapter()Retrieve the current adapter supplying pages. voidaddOnAdapterChangeListener(@NonNull() ViewPager.OnAdapterChangeListener listener)Add a listener that will be invoked whenever the adapter for this ViewPager changes. voidremoveOnAdapterChangeListener(@NonNull() ViewPager.OnAdapterChangeListener listener)Remove a listener that was previously added via addOnAdapterChangeListener. voidsetCurrentItem(int item)Set the currently selected page. voidsetCurrentItem(int item, boolean smoothScroll)Set the currently selected page. intgetCurrentItem()voidsetOnPageChangeListener(ViewPager.OnPageChangeListener listener)Set a listener that will be invoked whenever the page changes or is incrementallyscrolled. voidaddOnPageChangeListener(@NonNull() ViewPager.OnPageChangeListener listener)Add a listener that will be invoked whenever the page changes or is incrementallyscrolled. voidremoveOnPageChangeListener(@NonNull() ViewPager.OnPageChangeListener listener)Remove a listener that was previously added via addOnPageChangeListener. voidclearOnPageChangeListeners()Remove all listeners that are notified of any changes in scroll state or position. voidsetPageTransformer(boolean reverseDrawingOrder, @Nullable() ViewPager.PageTransformer transformer)Sets a PageTransformer that will be called for each attached page wheneverthe scroll position is changed. voidsetPageTransformer(boolean reverseDrawingOrder, @Nullable() ViewPager.PageTransformer transformer, int pageLayerType)Sets a PageTransformer that will be called for each attached page wheneverthe scroll position is changed. intgetOffscreenPageLimit()Returns the number of pages that will be retained to either side of thecurrent page in the view hierarchy in an idle state. voidsetOffscreenPageLimit(int limit)Set the number of pages that should be retained to either side of thecurrent page in the view hierarchy in an idle state. voidsetPageMargin(int marginPixels)Set the margin between pages. intgetPageMargin()Return the margin between pages. voidsetPageMarginDrawable(@Nullable() Drawable d)Set a drawable that will be used to fill the margin between pages. voidsetPageMarginDrawable(@DrawableRes() int resId)Set a drawable that will be used to fill the margin between pages. ParcelableonSaveInstanceState()voidonRestoreInstanceState(Parcelable state)voidaddView(View child, int index, ViewGroup.LayoutParams params)voidremoveView(View view)voidcomputeScroll()booleanonInterceptTouchEvent(MotionEvent ev)booleanonTouchEvent(MotionEvent ev)voiddraw(Canvas canvas)booleanbeginFakeDrag()Start a fake drag of the pager. voidendFakeDrag()End a fake drag of the pager. voidfakeDragBy(float xOffset)Fake drag by an offset in pixels. booleanisFakeDragging()Returns true if a fake drag is in progress. booleancanScrollHorizontally(int direction)Check if this ViewPager can be scrolled horizontally in a certain direction. booleandispatchKeyEvent(KeyEvent event)booleanexecuteKeyEvent(@NonNull() KeyEvent event)You can call this function yourself to have the scroll view performscrolling from a key event, just as if the event had been dispatched toit by the view hierarchy. booleanarrowScroll(int direction)Handle scrolling in response to a left or right arrow click. voidaddFocusables(ArrayList<View> views, int direction, int focusableMode)We only want the current page that is being shown to be focusable. voidaddTouchables(ArrayList<View> views)We only want the current page that is being shown to be touchable. ViewGroup.LayoutParamsgenerateLayoutParams(AttributeSet attrs)-
Methods inherited from class android.view.ViewGroup
addChildrenForAccessibility, addExtraDataToAccessibilityNodeInfo, addFocusables, addKeyboardNavigationClusters, addStatesFromChildren, addTouchables, addView, bringChildToFront, childDrawableStateChanged, childHasTransientStateChanged, clearChildFocus, clearDisappearingChildren, clearFocus, dispatchApplyWindowInsets, dispatchCapturedPointerEvent, dispatchConfigurationChanged, dispatchDisplayHint, dispatchDragEvent, dispatchDrawableHotspotChanged, dispatchFinishTemporaryDetach, dispatchKeyEvent, dispatchKeyEventPreIme, dispatchKeyShortcutEvent, dispatchPointerCaptureChanged, dispatchProvideAutofillStructure, dispatchProvideStructure, dispatchSetActivated, dispatchSetSelected, dispatchStartTemporaryDetach, dispatchSystemUiVisibilityChanged, dispatchTouchEvent, dispatchTrackballEvent, dispatchUnhandledMove, dispatchWindowFocusChanged, dispatchWindowInsetsAnimationEnd, dispatchWindowInsetsAnimationPrepare, dispatchWindowInsetsAnimationProgress, dispatchWindowInsetsAnimationStart, dispatchWindowSystemUiVisiblityChanged, dispatchWindowVisibilityChanged, endViewTransition, findFocus, findViewsWithText, focusSearch, focusableViewAvailable, gatherTransparentRegion, generateLayoutParams, getAccessibilityClassName, getChildAt, getChildCount, getChildMeasureSpec, getChildVisibleRect, getClipChildren, getClipToPadding, getDescendantFocusability, getFocusedChild, getLayoutAnimation, getLayoutAnimationListener, getLayoutMode, getLayoutTransition, getNestedScrollAxes, getOverlay, getPersistentDrawingCache, getTouchscreenBlocksFocus, hasFocus, hasTransientState, indexOfChild, invalidateChild, invalidateChildInParent, isAlwaysDrawnWithCacheEnabled, isAnimationCacheEnabled, isLayoutSuppressed, isMotionEventSplittingEnabled, isTransitionGroup, jumpDrawablesToCurrentState, layout, notifySubtreeAccessibilityStateChanged, offsetDescendantRectToMyCoords, offsetRectIntoDescendantCoords, onDescendantInvalidated, onInterceptHoverEvent, onInterceptTouchEvent, onNestedFling, onNestedPreFling, onNestedPrePerformAccessibilityAction, onNestedPreScroll, onNestedScroll, onNestedScrollAccepted, onRequestSendAccessibilityEvent, onResolvePointerIcon, onStartNestedScroll, onStopNestedScroll, onViewAdded, onViewRemoved, recomputeViewAttributes, removeAllViews, removeAllViewsInLayout, removeView, removeViewAt, removeViewInLayout, removeViews, removeViewsInLayout, requestChildFocus, requestChildRectangleOnScreen, requestDisallowInterceptTouchEvent, requestFocus, requestSendAccessibilityEvent, requestTransparentRegion, restoreDefaultFocus, scheduleLayoutAnimation, setAddStatesFromChildren, setAlwaysDrawnWithCacheEnabled, setAnimationCacheEnabled, setClipChildren, setClipToPadding, setDescendantFocusability, setLayoutAnimation, setLayoutAnimationListener, setLayoutMode, setLayoutTransition, setMotionEventSplittingEnabled, setOnHierarchyChangeListener, setPersistentDrawingCache, setTouchscreenBlocksFocus, setTransitionGroup, setWindowInsetsAnimationCallback, shouldDelayChildPressedState, showContextMenuForChild, startActionModeForChild, startLayoutAnimation, startViewTransition, suppressLayout, updateViewLayout -
Methods inherited from class android.view.View
addOnAttachStateChangeListener, addOnLayoutChangeListener, addOnUnhandledKeyEventListener, animate, announceForAccessibility, autofill, bringToFront, buildDrawingCache, buildLayer, callOnClick, canResolveLayoutDirection, canResolveTextAlignment, canResolveTextDirection, canScrollHorizontally, canScrollVertically, cancelDragAndDrop, cancelLongPress, cancelPendingInputEvents, checkInputConnectionProxy, clearAnimation, combineMeasuredStates, computeScroll, computeSystemWindowInsets, createAccessibilityNodeInfo, createContextMenu, destroyDrawingCache, dispatchGenericMotionEvent, dispatchNestedFling, dispatchNestedPreFling, dispatchNestedPrePerformAccessibilityAction, dispatchNestedPreScroll, dispatchNestedScroll, dispatchPopulateAccessibilityEvent, draw, drawableHotspotChanged, findViewById, findViewWithTag, forceHasOverlappingRendering, forceLayout, generateViewId, getAccessibilityDelegate, getAccessibilityLiveRegion, getAccessibilityNodeProvider, getAccessibilityPaneTitle, getAccessibilityTraversalAfter, getAccessibilityTraversalBefore, getAlpha, getAnimation, getAnimationMatrix, getApplicationWindowToken, getAttributeResolutionStack, getAttributeSourceResourceMap, getAutofillHints, getAutofillId, getAutofillType, getAutofillValue, getBackground, getBackgroundTintBlendMode, getBackgroundTintList, getBackgroundTintMode, getBaseline, getBottom, getCameraDistance, getClipBounds, getClipBounds, getClipToOutline, getContentCaptureSession, getContentDescription, getContext, getDefaultFocusHighlightEnabled, getDefaultSize, getDisplay, getDrawableState, getDrawingCache, getDrawingCacheBackgroundColor, getDrawingCacheQuality, getDrawingRect, getDrawingTime, getElevation, getExplicitStyle, getFilterTouchesWhenObscured, getFitsSystemWindows, getFocusable, getFocusables, getFocusedRect, getForeground, getForegroundGravity, getForegroundTintBlendMode, getForegroundTintList, getForegroundTintMode, getGlobalVisibleRect, getHandler, getHasOverlappingRendering, getHeight, getHitRect, getHorizontalFadingEdgeLength, getHorizontalScrollbarThumbDrawable, getHorizontalScrollbarTrackDrawable, getId, getImportantForAccessibility, getImportantForAutofill, getImportantForContentCapture, getKeepScreenOn, getKeyDispatcherState, getLabelFor, getLayerType, getLayoutDirection, getLayoutParams, getLeft, getLocalVisibleRect, getLocationInSurface, getLocationInWindow, getLocationOnScreen, getMatrix, getMeasuredHeight, getMeasuredHeightAndState, getMeasuredState, getMeasuredWidth, getMeasuredWidthAndState, getMinimumHeight, getMinimumWidth, getNextClusterForwardId, getNextFocusDownId, getNextFocusForwardId, getNextFocusLeftId, getNextFocusRightId, getNextFocusUpId, getOnFocusChangeListener, getOutlineAmbientShadowColor, getOutlineProvider, getOutlineSpotShadowColor, getOverScrollMode, getOverlay, getPaddingBottom, getPaddingEnd, getPaddingLeft, getPaddingRight, getPaddingStart, getPaddingTop, getParent, getParentForAccessibility, getPivotX, getPivotY, getPointerIcon, getResources, getRevealOnFocusHint, getRight, getRootView, getRootWindowInsets, getRotation, getRotationX, getRotationY, getScaleX, getScaleY, getScrollBarDefaultDelayBeforeFade, getScrollBarFadeDuration, getScrollBarSize, getScrollBarStyle, getScrollIndicators, getScrollX, getScrollY, getSolidColor, getSourceLayoutResId, getStateDescription, getStateListAnimator, getSystemGestureExclusionRects, getSystemUiVisibility, getTag, getTextAlignment, getTextDirection, getTooltipText, getTop, getTouchDelegate, getTouchables, getTransitionAlpha, getTransitionName, getTranslationX, getTranslationY, getTranslationZ, getUniqueDrawingId, getVerticalFadingEdgeLength, getVerticalScrollbarPosition, getVerticalScrollbarThumbDrawable, getVerticalScrollbarTrackDrawable, getVerticalScrollbarWidth, getViewTreeObserver, getVisibility, getWidth, getWindowId, getWindowInsetsController, getWindowSystemUiVisibility, getWindowToken, getWindowVisibility, getWindowVisibleDisplayFrame, getX, getY, getZ, hasExplicitFocusable, hasFocusable, hasNestedScrollingParent, hasOnClickListeners, hasOnLongClickListeners, hasOverlappingRendering, hasPointerCapture, hasWindowFocus, inflate, invalidate, invalidateDrawable, invalidateOutline, isAccessibilityFocused, isAccessibilityHeading, isActivated, isAttachedToWindow, isClickable, isContextClickable, isDirty, isDrawingCacheEnabled, isDuplicateParentStateEnabled, isEnabled, isFocusable, isFocusableInTouchMode, isFocused, isFocusedByDefault, isForceDarkAllowed, isHapticFeedbackEnabled, isHardwareAccelerated, isHorizontalFadingEdgeEnabled, isHorizontalScrollBarEnabled, isHovered, isImportantForAccessibility, isImportantForAutofill, isImportantForContentCapture, isInEditMode, isInLayout, isInTouchMode, isKeyboardNavigationCluster, isLaidOut, isLayoutDirectionResolved, isLayoutRequested, isLongClickable, isNestedScrollingEnabled, isOpaque, isPaddingRelative, isPivotSet, isPressed, isSaveEnabled, isSaveFromParentEnabled, isScreenReaderFocusable, isScrollContainer, isScrollbarFadingEnabled, isSelected, isShowingLayoutBounds, isShown, isSoundEffectsEnabled, isTemporarilyDetached, isTextAlignmentResolved, isTextDirectionResolved, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, isVisibleToUserForAutofill, keyboardNavigationClusterSearch, measure, offsetLeftAndRight, offsetTopAndBottom, onApplyWindowInsets, onCancelPendingInputEvents, onCapturedPointerEvent, onCheckIsTextEditor, onCreateInputConnection, onDragEvent, onDrawForeground, onFilterTouchEventForSecurity, onFinishTemporaryDetach, onGenericMotionEvent, onHoverChanged, onHoverEvent, onInitializeAccessibilityEvent, onInitializeAccessibilityNodeInfo, onKeyDown, onKeyLongPress, onKeyMultiple, onKeyPreIme, onKeyShortcut, onKeyUp, onPointerCaptureChange, onPopulateAccessibilityEvent, onProvideAutofillStructure, onProvideAutofillVirtualStructure, onProvideContentCaptureStructure, onProvideStructure, onProvideVirtualStructure, onRtlPropertiesChanged, onScreenStateChanged, onStartTemporaryDetach, onTouchEvent, onTrackballEvent, onVisibilityAggregated, onWindowFocusChanged, onWindowSystemUiVisibilityChanged, performAccessibilityAction, performClick, performContextClick, performHapticFeedback, performLongClick, playSoundEffect, post, postDelayed, postInvalidate, postInvalidateDelayed, postInvalidateOnAnimation, postOnAnimation, postOnAnimationDelayed, refreshDrawableState, releasePointerCapture, removeCallbacks, removeOnAttachStateChangeListener, removeOnLayoutChangeListener, removeOnUnhandledKeyEventListener, requestApplyInsets, requestFitSystemWindows, requestFocusFromTouch, requestLayout, requestPointerCapture, requestRectangleOnScreen, requestUnbufferedDispatch, requireViewById, resetPivot, resolveSize, resolveSizeAndState, restoreHierarchyState, saveAttributeDataForStyleable, saveHierarchyState, scheduleDrawable, scrollBy, scrollTo, sendAccessibilityEvent, sendAccessibilityEventUnchecked, setAccessibilityDelegate, setAccessibilityHeading, setAccessibilityLiveRegion, setAccessibilityPaneTitle, setAccessibilityTraversalAfter, setAccessibilityTraversalBefore, setActivated, setAlpha, setAnimation, setAnimationMatrix, setAutofillHints, setAutofillId, setBackground, setBackgroundColor, setBackgroundDrawable, setBackgroundResource, setBackgroundTintBlendMode, setBackgroundTintList, setBackgroundTintMode, setBottom, setCameraDistance, setClickable, setClipBounds, setClipToOutline, setContentCaptureSession, setContentDescription, setContextClickable, setDefaultFocusHighlightEnabled, setDrawingCacheBackgroundColor, setDrawingCacheEnabled, setDrawingCacheQuality, setDuplicateParentStateEnabled, setElevation, setEnabled, setFadingEdgeLength, setFilterTouchesWhenObscured, setFitsSystemWindows, setFocusable, setFocusableInTouchMode, setFocusedByDefault, setForceDarkAllowed, setForeground, setForegroundGravity, setForegroundTintBlendMode, setForegroundTintList, setForegroundTintMode, setHapticFeedbackEnabled, setHasTransientState, setHorizontalFadingEdgeEnabled, setHorizontalScrollBarEnabled, setHorizontalScrollbarThumbDrawable, setHorizontalScrollbarTrackDrawable, setHovered, setId, setImportantForAccessibility, setImportantForAutofill, setImportantForContentCapture, setKeepScreenOn, setKeyboardNavigationCluster, setLabelFor, setLayerPaint, setLayerType, setLayoutDirection, setLayoutParams, setLeft, setLeftTopRightBottom, setLongClickable, setMinimumHeight, setMinimumWidth, setNestedScrollingEnabled, setNextClusterForwardId, setNextFocusDownId, setNextFocusForwardId, setNextFocusLeftId, setNextFocusRightId, setNextFocusUpId, setOnApplyWindowInsetsListener, setOnCapturedPointerListener, setOnClickListener, setOnContextClickListener, setOnCreateContextMenuListener, setOnDragListener, setOnFocusChangeListener, setOnGenericMotionListener, setOnHoverListener, setOnKeyListener, setOnLongClickListener, setOnScrollChangeListener, setOnSystemUiVisibilityChangeListener, setOnTouchListener, setOutlineAmbientShadowColor, setOutlineProvider, setOutlineSpotShadowColor, setOverScrollMode, setPadding, setPaddingRelative, setPivotX, setPivotY, setPointerIcon, setPressed, setRevealOnFocusHint, setRight, setRotation, setRotationX, setRotationY, setSaveEnabled, setSaveFromParentEnabled, setScaleX, setScaleY, setScreenReaderFocusable, setScrollBarDefaultDelayBeforeFade, setScrollBarFadeDuration, setScrollBarSize, setScrollBarStyle, setScrollContainer, setScrollIndicators, setScrollX, setScrollY, setScrollbarFadingEnabled, setSelected, setSoundEffectsEnabled, setStateDescription, setStateListAnimator, setSystemGestureExclusionRects, setSystemUiVisibility, setTag, setTextAlignment, setTextDirection, setTooltipText, setTop, setTouchDelegate, setTransitionAlpha, setTransitionName, setTransitionVisibility, setTranslationX, setTranslationY, setTranslationZ, setVerticalFadingEdgeEnabled, setVerticalScrollBarEnabled, setVerticalScrollbarPosition, setVerticalScrollbarThumbDrawable, setVerticalScrollbarTrackDrawable, setVisibility, setWillNotCacheDrawing, setWillNotDraw, setX, setY, setZ, showContextMenu, startActionMode, startAnimation, startDrag, startDragAndDrop, startNestedScroll, stopNestedScroll, toString, transformMatrixToGlobal, transformMatrixToLocal, unscheduleDrawable, updateDragShadow, willNotCacheDrawing, willNotDraw -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
ViewPager
ViewPager(Context context)
-
ViewPager
ViewPager(Context context, AttributeSet attrs)
-
-
Method Detail
-
setAdapter
void setAdapter(@Nullable() PagerAdapter adapter)
Set a PagerAdapter that will supply views for this pager as needed.
- Parameters:
adapter- Adapter to use
-
getAdapter
@Nullable() PagerAdapter getAdapter()
Retrieve the current adapter supplying pages.
-
addOnAdapterChangeListener
void addOnAdapterChangeListener(@NonNull() ViewPager.OnAdapterChangeListener listener)
Add a listener that will be invoked whenever the adapter for this ViewPager changes.
- Parameters:
listener- listener to add
-
removeOnAdapterChangeListener
void removeOnAdapterChangeListener(@NonNull() ViewPager.OnAdapterChangeListener listener)
Remove a listener that was previously added via addOnAdapterChangeListener.
- Parameters:
listener- listener to remove
-
setCurrentItem
void setCurrentItem(int item)
Set the currently selected page. If the ViewPager has already been through its firstlayout with its current adapter there will be a smooth animated transition betweenthe current item and the specified item.
- Parameters:
item- Item index to select
-
setCurrentItem
void setCurrentItem(int item, boolean smoothScroll)
Set the currently selected page.
- Parameters:
item- Item index to selectsmoothScroll- True to smoothly scroll to the new item, false to transition immediately
-
getCurrentItem
int getCurrentItem()
-
setOnPageChangeListener
@Deprecated() void setOnPageChangeListener(ViewPager.OnPageChangeListener listener)
Set a listener that will be invoked whenever the page changes or is incrementallyscrolled. See OnPageChangeListener.
- Parameters:
listener- Listener to set
-
addOnPageChangeListener
void addOnPageChangeListener(@NonNull() ViewPager.OnPageChangeListener listener)
Add a listener that will be invoked whenever the page changes or is incrementallyscrolled. 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:
listener- listener to add
-
removeOnPageChangeListener
void removeOnPageChangeListener(@NonNull() ViewPager.OnPageChangeListener listener)
Remove a listener that was previously added via addOnPageChangeListener.
- Parameters:
listener- listener to remove
-
clearOnPageChangeListeners
void clearOnPageChangeListeners()
Remove all listeners that are notified of any changes in scroll state or position.
-
setPageTransformer
void setPageTransformer(boolean reverseDrawingOrder, @Nullable() ViewPager.PageTransformer transformer)
Sets a PageTransformer that will be called for each attached page wheneverthe scroll position is changed. This allows the application to apply custom propertytransformations 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
{@code pageLayerType}.- Parameters:
reverseDrawingOrder- true if the supplied PageTransformer requires page viewsto be drawn from last to first instead of first to last.transformer- PageTransformer that will modify each page's animation properties
-
setPageTransformer
void setPageTransformer(boolean reverseDrawingOrder, @Nullable() ViewPager.PageTransformer transformer, int pageLayerType)
Sets a PageTransformer that will be called for each attached page wheneverthe scroll position is changed. This allows the application to apply custom propertytransformations to each page, overriding the default sliding behavior.
- Parameters:
reverseDrawingOrder- true if the supplied PageTransformer requires page viewsto be drawn from last to first instead of first to last.transformer- PageTransformer that will modify each page's animation propertiespageLayerType- View layer type that should be used for ViewPager pages.
-
getOffscreenPageLimit
int getOffscreenPageLimit()
Returns the number of pages that will be retained to either side of thecurrent page in the view hierarchy in an idle state. Defaults to 1.
-
setOffscreenPageLimit
void setOffscreenPageLimit(int limit)
Set the number of pages that should be retained to either side of thecurrent page in the view hierarchy in an idle state. Pages beyond thislimit will be recreated from the adapter when needed.
This is offered as an optimization. If you know in advance the numberof pages you will need to support or have lazy-loading mechanisms in placeon your pages, tweaking this setting can have benefits in perceived smoothnessof 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 fornewly 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:
limit- How many pages will be kept offscreen in an idle state.
-
setPageMargin
void setPageMargin(int marginPixels)
Set the margin between pages.
- Parameters:
marginPixels- Distance between adjacent pages in pixels
-
getPageMargin
int getPageMargin()
Return the margin between pages.
-
setPageMarginDrawable
void setPageMarginDrawable(@Nullable() Drawable d)
Set a drawable that will be used to fill the margin between pages.
- Parameters:
d- Drawable to display between pages
-
setPageMarginDrawable
void setPageMarginDrawable(@DrawableRes() int resId)
Set a drawable that will be used to fill the margin between pages.
- Parameters:
resId- Resource ID of a drawable to display between pages
-
onSaveInstanceState
Parcelable onSaveInstanceState()
-
onRestoreInstanceState
void onRestoreInstanceState(Parcelable state)
-
addView
void addView(View child, int index, ViewGroup.LayoutParams params)
-
removeView
void removeView(View view)
-
computeScroll
void computeScroll()
-
onInterceptTouchEvent
boolean onInterceptTouchEvent(MotionEvent ev)
-
onTouchEvent
boolean onTouchEvent(MotionEvent ev)
-
beginFakeDrag
boolean beginFakeDrag()
Start a fake drag of the pager.
A fake drag can be useful if you want to synchronize the motion of the ViewPagerwith the touch scrolling of another view, while still letting the ViewPagercontrol 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 dragis already in progress, this method will return false.
-
endFakeDrag
void endFakeDrag()
End a fake drag of the pager.
-
fakeDragBy
void fakeDragBy(float xOffset)
Fake drag by an offset in pixels. You must have called beginFakeDrag first.
- Parameters:
xOffset- Offset in pixels to drag by.
-
isFakeDragging
boolean isFakeDragging()
Returns true if a fake drag is in progress.
-
canScrollHorizontally
boolean canScrollHorizontally(int direction)
Check if this ViewPager can be scrolled horizontally in a certain direction.
- Parameters:
direction- Negative to check scrolling left, positive to check scrolling right.
-
dispatchKeyEvent
boolean dispatchKeyEvent(KeyEvent event)
-
executeKeyEvent
boolean executeKeyEvent(@NonNull() KeyEvent event)
You can call this function yourself to have the scroll view performscrolling from a key event, just as if the event had been dispatched toit by the view hierarchy.
- Parameters:
event- The key event to execute.
-
arrowScroll
boolean arrowScroll(int direction)
Handle scrolling in response to a left or right arrow click.
- Parameters:
direction- The direction corresponding to the arrow key that was pressed.
-
addFocusables
void addFocusables(ArrayList<View> views, int direction, int focusableMode)
We only want the current page that is being shown to be focusable.
-
addTouchables
void addTouchables(ArrayList<View> views)
We only want the current page that is being shown to be touchable.
-
generateLayoutParams
ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs)
-
-
-
-