ViewPager


class ViewPager : ViewGroup

Known direct subclasses
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)
@Target(value = ElementType.TYPE)
@Inherited
annotation ViewPager.DecorView

Annotation which allows marking of views to be decoration views when added to a view pager.

Layout parameters that should be supplied for views added to a ViewPager.

Callback interface for responding to adapter changes.

Callback interface for responding to changing state of the selected page.

A PageTransformer is invoked whenever a visible/attached page is scrolled.

This is the persistent state that is saved by ViewPager.

Simple implementation of the OnPageChangeListener interface with stub implementations of each method.

Constants

const Int

Indicates that the pager is currently being dragged by the user.

const Int

Indicates that the pager is in an idle, settled state.

const Int

Indicates that the pager is in the process of settling to a final position.

Public constructors

ViewPager(context: Context)
ViewPager(context: Context, attrs: AttributeSet?)

Public functions

Unit
addFocusables(views: ArrayList<View!>!, direction: Int, focusableMode: Int)

We only want the current page that is being shown to be focusable.

Unit

Add a listener that will be invoked whenever the adapter for this ViewPager changes.

Unit

Add a listener that will be invoked whenever the page changes or is incrementally scrolled.

Unit

We only want the current page that is being shown to be touchable.

Unit
addView(child: View!, index: Int, params: ViewGroup.LayoutParams!)
Boolean
arrowScroll(direction: Int)

Handle scrolling in response to a left or right arrow click.

Boolean

Start a fake drag of the pager.

Boolean

Check if this ViewPager can be scrolled horizontally in a certain direction.

Unit

Remove all listeners that are notified of any changes in scroll state or position.

Unit
Boolean
Boolean
Unit
draw(canvas: Canvas)
Unit

End a fake drag of the pager.

Boolean

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.

Unit
fakeDragBy(xOffset: Float)

Fake drag by an offset in pixels.

ViewGroup.LayoutParams!
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
Unit
Parcelable
Boolean
Unit

Remove a listener that was previously added via addOnAdapterChangeListener.

Unit

Remove a listener that was previously added via addOnPageChangeListener.

Unit
removeView(view: View!)
Unit

Set a PagerAdapter that will supply views for this pager as needed.

Unit

Set the currently selected page.

Unit
setCurrentItem(item: Int, smoothScroll: Boolean)

Set the currently selected page.

Unit

Set whether ViewPager should consume drag events if they are within the gutter (left and right edges) of the ViewPager.

Unit

Set the number of pages that should be retained to either side of the current page in the view hierarchy in an idle state.

Unit

This function is deprecated.

Use addOnPageChangeListener and removeOnPageChangeListener instead.

Unit
setPageMargin(marginPixels: Int)

Set the margin between pages.

Unit

Set a drawable that will be used to fill the margin between pages.

Unit

Set a drawable that will be used to fill the margin between pages.

Unit
setPageTransformer(
    reverseDrawingOrder: Boolean,
    transformer: ViewPager.PageTransformer?
)

Sets a PageTransformer that will be called for each attached page whenever the scroll position is changed.

Unit
setPageTransformer(
    reverseDrawingOrder: Boolean,
    transformer: ViewPager.PageTransformer?,
    pageLayerType: Int
)

Sets a PageTransformer that will be called for each attached page whenever the scroll position is changed.

Protected functions

Boolean
canScroll(v: View, checkV: Boolean, dx: Int, x: Int, y: Int)

Tests scrollability within child views of v given a delta of dx.

Boolean
Unit
ViewGroup.LayoutParams!
ViewGroup.LayoutParams!
Int
getChildDrawingOrder(childCount: Int, i: Int)
Unit
Unit
Unit
onDraw(canvas: Canvas)
Unit
onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int)
Unit
onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int)
Unit
@CallSuper
onPageScrolled(position: Int, offset: Float, offsetPixels: Int)

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.

Boolean
onRequestFocusInDescendants(direction: Int, previouslyFocusedRect: Rect!)

We only want the current page that is being shown to be focusable.

Unit
onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int)
Boolean

Inherited Constants

From android.view.View
const Int
const Int
const Int
const Int
const Int
const Int
const Property<View!, Float!>!
const Int
const String!
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE = "creditCardExpirationDate"
const String!
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY = "creditCardExpirationDay"
const String!
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH = "creditCardExpirationMonth"
const String!
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR = "creditCardExpirationYear"
const String!
const String!
AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE = "creditCardSecurityCode"
const String!
const String!
const String!
const String!
const String!
const String!
const String!
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const Int
const Int
const Int
const Int
const Int
const Int
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const Int
const Int
const Int
const Int
const Int
const Int
const Int
GONE = 8
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
KEEP_SCREEN_ON = 67108864
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
NO_ID = -1
const Int
const Int
const Int
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const IntArray<Int>!
const Property<View!, Float!>!
const Property<View!, Float!>!
const Property<View!, Float!>!
const Property<View!, Float!>!
const Property<View!, Float!>!
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const IntArray<Int>!
const IntArray<Int>!
const Int
const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Int
const Property<View!, Float!>!
const Property<View!, Float!>!
const Property<View!, Float!>!
const String!
VIEW_LOG_TAG = "View"
const Int
const IntArray<Int>!
const Property<View!, Float!>!
const Property<View!, Float!>!
const Property<View!, Float!>!
From android.view.ViewGroup
const Int
const Int
const Int
const Int
const Int
const Int
const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

const Int

This property is deprecated.

Inherited functions

From android.view.View
Unit
Unit
Unit
ViewPropertyAnimator!
Unit
Unit
Boolean
Unit
Unit

This function is deprecated.

Unit
Boolean
Boolean
Boolean
Boolean
Boolean
Unit
Unit
Unit
Boolean
Unit
Unit
java-static Int
combineMeasuredStates(curState: Int, newState: Int)
Int
Int
Int
WindowInsets!
computeSystemWindowInsets(in: WindowInsets!, outLocalInsets: Rect!)
Int
Int
Int
AccessibilityNodeInfo!
Unit
Unit

This function is deprecated.

Boolean
Boolean
dispatchNestedFling(velocityX: Float, velocityY: Float, consumed: Boolean)
Boolean
dispatchNestedPreFling(velocityX: Float, velocityY: Float)
Boolean
dispatchNestedPrePerformAccessibilityAction(
    action: Int,
    arguments: Bundle!
)
Boolean
dispatchNestedPreScroll(
    dx: Int,
    dy: Int,
    consumed: IntArray!,
    offsetInWindow: IntArray!
)
Boolean
dispatchNestedScroll(
    dxConsumed: Int,
    dyConsumed: Int,
    dxUnconsumed: Int,
    dyUnconsumed: Int,
    offsetInWindow: IntArray!
)
Unit
OnBackInvokedDispatcher!
T!
<T : View?> findViewById(id: Int)
T!
<T : View?> findViewWithTag(tag: Any!)
Boolean

This function is deprecated.

Unit
forceHasOverlappingRendering(hasOverlappingRendering: Boolean)
Unit
Unit
generateDisplayHash(
    hashAlgorithm: String!,
    bounds: Rect!,
    executor: Executor!,
    callback: DisplayHashResultCallback!
)
java-static Int
View.AccessibilityDelegate!
Int
AccessibilityNodeProvider!
CharSequence!
Int
Int
String!
String!
Float
Animation!
Matrix!
IBinder!
IntArray<Int>!
(Mutable)Map<Int!, Int!>!
Array<String!>!
AutofillId!
Int
AutofillValue!
Drawable!
BlendMode!
ColorStateList!
PorterDuff.Mode!
Int
Int
Float
Int
Float
Rect!
Boolean
getClipBounds(outRect: Rect!)
Boolean
ContentCaptureSession!
CharSequence!
Context!
ContextMenu.ContextMenuInfo!
Boolean
java-static Int
getDefaultSize(size: Int, measureSpec: Int)
Display!
IntArray<Int>!
Bitmap!

This function is deprecated.

Int

This function is deprecated.

Int

This function is deprecated.

Unit
getDrawingRect(outRect: Rect!)
Long
Float
Int
Boolean
Boolean
Int
ArrayList<View!>!
getFocusables(direction: Int)
Unit
Drawable!
Int
BlendMode!
ColorStateList!
PorterDuff.Mode!
Boolean
getGlobalVisibleRect(r: Rect!, globalOffset: Point!)
Handler!
Float
Float
Float
Float
Runnable!
Boolean
Int
Unit
getHitRect(outRect: Rect!)
Int
Int
Drawable!
Drawable!
Int
Int
Int
Int
Boolean
KeyEvent.DispatcherState!
Int
Int
Int
ViewGroup.LayoutParams!
Int
Float
Int
Boolean
Unit
Unit
Unit
Matrix!
Int
Int
Int
Int
Int
Int
Int
Int
Int
Int
Int
Int
Int
View.OnFocusChangeListener!
Int
ViewOutlineProvider!
Int
Int
ViewOverlay!
Int
Int
Int
Int
Int
Int
ViewParent!
ViewParent!
Float
Float
PointerIcon!
(Mutable)List<Rect!>!
Array<String!>!
Resources!
Boolean
Int
Float
Int
AttachedSurfaceControl!
View!
WindowInsets!
Float
Float
Float
Float
Float
Int
Int
Int
Int
Int
Int
Int
Int
Int
Int
CharSequence!
StateListAnimator!
Int
Int
(Mutable)List<Rect!>!
Int

This function is deprecated.

Any!
Int
Int
CharSequence!
Int
Float
Int
TouchDelegate!
ArrayList<View!>!
Float
String!
Float
Float
Float
Long
Int
Int
Drawable!
Drawable!
Int
ViewTranslationResponse!
ViewTreeObserver!
Int
Int
Int
WindowId!
WindowInsetsController!
Int

This function is deprecated.

IBinder!
Int
Unit
Float
Float
Float
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
java-static View!
inflate(context: Context!, resource: Int, root: ViewGroup!)
Unit
invalidate(dirty: Rect!)

This function is deprecated.

Unit
Unit
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean

This function is deprecated.

Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
Boolean
View!
keyboardNavigationClusterSearch(currentCluster: View!, direction: Int)
Unit
measure(widthMeasureSpec: Int, heightMeasureSpec: Int)
java-static IntArray<Int>!
mergeDrawableStates(baseState: IntArray!, additionalState: IntArray!)
Unit
Unit
Unit
Unit
WindowInsets!
Unit
Boolean
Boolean
Unit
Unit
InputConnection!
Unit
onCreateViewTranslationRequest(
    supportedFormats: IntArray!,
    requestsCollector: Consumer<ViewTranslationRequest!>!
)
Unit
onCreateVirtualViewTranslationRequests(
    virtualIds: LongArray!,
    supportedFormats: IntArray!,
    requestsCollector: Consumer<ViewTranslationRequest!>!
)
Unit
Boolean
Unit
Unit
Boolean
Unit
Unit
Unit
onFocusChanged(
    gainFocus: Boolean,
    direction: Int,
    previouslyFocusedRect: Rect!
)
Boolean
Unit
Boolean
Unit
Unit
Boolean
onKeyDown(keyCode: Int, event: KeyEvent!)
Boolean
onKeyLongPress(keyCode: Int, event: KeyEvent!)
Boolean
onKeyMultiple(keyCode: Int, repeatCount: Int, event: KeyEvent!)
Boolean
onKeyPreIme(keyCode: Int, event: KeyEvent!)
Boolean
onKeyShortcut(keyCode: Int, event: KeyEvent!)
Boolean
onKeyUp(keyCode: Int, event: KeyEvent!)
Unit
onOverScrolled(
    scrollX: Int,
    scrollY: Int,
    clampedX: Boolean,
    clampedY: Boolean
)
Unit
Unit
Unit
Unit
Unit
Unit
Unit
ContentInfo!
Unit
onRtlPropertiesChanged(layoutDirection: Int)
Unit
onScreenStateChanged(screenState: Int)
Unit
onScrollCaptureSearch(
    localVisibleRect: Rect!,
    windowOffset: Point!,
    targets: Consumer<ScrollCaptureTarget!>!
)
Unit
onScrollChanged(l: Int, t: Int, oldl: Int, oldt: Int)
Boolean
onSetAlpha(alpha: Int)
Unit
Boolean
Unit
Unit
Unit
Unit
onVisibilityChanged(changedView: View!, visibility: Int)
Unit
onWindowFocusChanged(hasWindowFocus: Boolean)
Unit

This function is deprecated.

Unit
Boolean
overScrollBy(
    deltaX: Int,
    deltaY: Int,
    scrollX: Int,
    scrollY: Int,
    scrollRangeX: Int,
    scrollRangeY: Int,
    maxOverScrollX: Int,
    maxOverScrollY: Int,
    isTouchEvent: Boolean
)
Boolean
performAccessibilityAction(action: Int, arguments: Bundle!)
Boolean
Boolean
Boolean
performHapticFeedback(feedbackConstant: Int)
Boolean
ContentInfo!
Unit
playSoundEffect(soundConstant: Int)
Boolean
post(action: Runnable!)
Boolean
postDelayed(action: Runnable!, delayMillis: Long)
Unit
Unit
postInvalidateDelayed(delayMilliseconds: Long)
Unit
Unit
Unit
postOnAnimationDelayed(action: Runnable!, delayMillis: Long)
Unit
Unit
Boolean
Unit
Unit
Unit
Unit
Unit

This function is deprecated.

Boolean
Unit
Unit
Boolean
Unit
T!
<T : View?> requireViewById(id: Int)
Unit
java-static Int
resolveSize(size: Int, measureSpec: Int)
java-static Int
resolveSizeAndState(size: Int, measureSpec: Int, childMeasuredState: Int)
Unit
Unit
saveAttributeDataForStyleable(
    context: Context!,
    styleable: IntArray!,
    attrs: AttributeSet!,
    t: TypedArray!,
    defStyleAttr: Int,
    defStyleRes: Int
)
Unit
Unit
scheduleDrawable(who: Drawable!, what: Runnable!, when: Long)
Unit
scrollBy(x: Int, y: Int)
Unit
scrollTo(x: Int, y: Int)
Unit
Unit
Unit
setAccessibilityDataSensitive(accessibilityDataSensitive: Int)
Unit
Unit
Unit
Unit
setAccessibilityPaneTitle(accessibilityPaneTitle: CharSequence!)
Unit
Unit
Unit
setActivated(activated: Boolean)
Unit
setAllowClickWhenDisabled(clickableWhenDisabled: Boolean)
Unit
Unit
Unit
setAlpha(alpha: Float)
Unit
setAnimation(animation: Animation!)
Unit
Unit
Unit
setAutofillHints(autofillHints: Array<String!>!)
Unit
Unit
setBackground(background: Drawable!)
Unit
Unit

This function is deprecated.

Unit
Unit
Unit
Unit
Unit
setBottom(bottom: Int)
Unit
Unit
setClickable(clickable: Boolean)
Unit
setClipBounds(clipBounds: Rect!)
Unit
setClipToOutline(clipToOutline: Boolean)
Unit
Unit
setContentDescription(contentDescription: CharSequence!)
Unit
setContextClickable(contextClickable: Boolean)
Unit
setDefaultFocusHighlightEnabled(defaultFocusHighlightEnabled: Boolean)
Unit

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit
Unit
setElevation(elevation: Float)
Unit
setEnabled(enabled: Boolean)
Unit
Unit
Unit
setFitsSystemWindows(fitSystemWindows: Boolean)
Unit
setFocusable(focusable: Boolean)
Unit
setFocusableInTouchMode(focusableInTouchMode: Boolean)
Unit
setFocusedByDefault(isFocusedByDefault: Boolean)
Unit
Unit
setForeground(foreground: Drawable!)
Unit
Unit
Unit
Unit
Unit
setHandwritingBoundsOffsets(
    offsetLeft: Float,
    offsetTop: Float,
    offsetRight: Float,
    offsetBottom: Float
)
Unit
Unit
setHapticFeedbackEnabled(hapticFeedbackEnabled: Boolean)
Unit
setHasTransientState(hasTransientState: Boolean)
Unit
setHorizontalFadingEdgeEnabled(horizontalFadingEdgeEnabled: Boolean)
Unit
setHorizontalScrollBarEnabled(horizontalScrollBarEnabled: Boolean)
Unit
Unit
Unit
setHovered(hovered: Boolean)
Unit
setId(id: Int)
Unit
Unit
Unit
Unit
setIsCredential(isCredential: Boolean)
Unit
setIsHandwritingDelegate(isHandwritingDelegate: Boolean)
Unit
setKeepScreenOn(keepScreenOn: Boolean)
Unit
Unit
Unit
Unit
setLayerType(layerType: Int, paint: Paint!)
Unit
setLayoutDirection(layoutDirection: Int)
Unit
Unit
setLeft(left: Int)
Unit
setLeftTopRightBottom(left: Int, top: Int, right: Int, bottom: Int)
Unit
setLongClickable(longClickable: Boolean)
Unit
setMeasuredDimension(measuredWidth: Int, measuredHeight: Int)
Unit
setMinimumHeight(minHeight: Int)
Unit
setMinimumWidth(minWidth: Int)
Unit
Unit
setNextClusterForwardId(nextClusterForwardId: Int)
Unit
setNextFocusDownId(nextFocusDownId: Int)
Unit
setNextFocusForwardId(nextFocusForwardId: Int)
Unit
setNextFocusLeftId(nextFocusLeftId: Int)
Unit
setNextFocusRightId(nextFocusRightId: Int)
Unit
setNextFocusUpId(nextFocusUpId: Int)
Unit
Unit
Unit
Unit
Unit
Unit
Unit
Unit
Unit
Unit
Unit
Unit
setOnReceiveContentListener(
    mimeTypes: Array<String!>!,
    listener: OnReceiveContentListener!
)
Unit
Unit

This function is deprecated.

Unit
Unit
Unit
Unit
Unit
setOverScrollMode(overScrollMode: Int)
Unit
setPadding(left: Int, top: Int, right: Int, bottom: Int)
Unit
setPaddingRelative(start: Int, top: Int, end: Int, bottom: Int)
Unit
setPivotX(pivotX: Float)
Unit
setPivotY(pivotY: Float)
Unit
setPointerIcon(pointerIcon: PointerIcon!)
Unit
setPreferKeepClear(preferKeepClear: Boolean)
Unit
Unit
setPressed(pressed: Boolean)
Unit
setRenderEffect(renderEffect: RenderEffect!)
Unit
setRevealOnFocusHint(revealOnFocus: Boolean)
Unit
setRight(right: Int)
Unit
setRotation(rotation: Float)
Unit
setRotationX(rotationX: Float)
Unit
setRotationY(rotationY: Float)
Unit
Unit
Unit
setScaleX(scaleX: Float)
Unit
setScaleY(scaleY: Float)
Unit
setScreenReaderFocusable(screenReaderFocusable: Boolean)
Unit
setScrollBarDefaultDelayBeforeFade(
    scrollBarDefaultDelayBeforeFade: Int
)
Unit
setScrollBarFadeDuration(scrollBarFadeDuration: Int)
Unit
setScrollBarSize(scrollBarSize: Int)
Unit
Unit
Unit
Unit
setScrollContainer(isScrollContainer: Boolean)
Unit
setScrollIndicators(indicators: Int)
Unit
setScrollX(value: Int)
Unit
setScrollY(value: Int)
Unit
Unit
setSelected(selected: Boolean)
Unit
setSoundEffectsEnabled(soundEffectsEnabled: Boolean)
Unit
setStateDescription(stateDescription: CharSequence!)
Unit
Unit
Unit

This function is deprecated.

Unit
setTag(tag: Any!)
Unit
setTextAlignment(textAlignment: Int)
Unit
setTextDirection(textDirection: Int)
Unit
Unit
setTop(top: Int)
Unit
Unit
Unit
setTransitionName(transitionName: String!)
Unit
Unit
setTranslationX(translationX: Float)
Unit
setTranslationY(translationY: Float)
Unit
setTranslationZ(translationZ: Float)
Unit
setVerticalFadingEdgeEnabled(verticalFadingEdgeEnabled: Boolean)
Unit
setVerticalScrollBarEnabled(verticalScrollBarEnabled: Boolean)
Unit
Unit
Unit
Unit
Unit
setVisibility(visibility: Int)
Unit
setWillNotCacheDrawing(willNotCacheDrawing: Boolean)

This function is deprecated.

Unit
setWillNotDraw(willNotDraw: Boolean)
Unit
setX(x: Float)
Unit
setY(y: Float)
Unit
setZ(z: Float)
Boolean
ActionMode!
Unit
Boolean
startDrag(
    data: ClipData!,
    shadowBuilder: View.DragShadowBuilder!,
    myLocalState: Any!,
    flags: Int
)

This function is deprecated.

Boolean
startDragAndDrop(
    data: ClipData!,
    shadowBuilder: View.DragShadowBuilder!,
    myLocalState: Any!,
    flags: Int
)
Boolean
Unit
String!
Unit
Unit
Unit
Unit
Boolean

This function is deprecated.

Boolean
From android.view.ViewGroup
Unit
Unit
addExtraDataToAccessibilityNodeInfo(
    info: AccessibilityNodeInfo!,
    extraDataKey: String!,
    arguments: Bundle!
)
Unit
addKeyboardNavigationClusters(
    views: (Mutable)Collection<View!>!,
    direction: Int
)
Boolean
Unit
addView(child: View!)
Boolean
addViewInLayout(child: View!, index: Int, params: ViewGroup.LayoutParams!)
Unit
attachLayoutAnimationParameters(
    child: View!,
    params: ViewGroup.LayoutParams!,
    index: Int,
    count: Int
)
Unit
attachViewToParent(child: View!, index: Int, params: ViewGroup.LayoutParams!)
Unit
Boolean
Unit
Unit
childHasTransientStateChanged(
    child: View!,
    childHasTransientState: Boolean
)
Unit
Unit
Unit
Unit
Unit
debug(depth: Int)
Unit
Unit
Unit
detachViewsFromParent(start: Int, count: Int)
WindowInsets!
Boolean
Unit
Unit
dispatchCreateViewTranslationRequest(
    viewIds: (Mutable)Map<AutofillId!, LongArray!>!,
    supportedFormats: IntArray!,
    capability: TranslationCapability!,
    requests: (Mutable)List<ViewTranslationRequest!>!
)
Unit
Boolean
Unit
dispatchDraw(canvas: Canvas!)
Unit
Unit
Unit
Boolean
Boolean
Boolean
Boolean
Boolean
Unit
Unit
Unit
Unit
Unit
Unit
dispatchScrollCaptureSearch(
    localVisibleRect: Rect!,
    windowOffset: Point!,
    targets: Consumer<ScrollCaptureTarget!>!
)
Unit
Unit
Unit
Unit
Unit

This function is deprecated.

Unit
Boolean
Boolean
Boolean
dispatchUnhandledMove(focused: View!, direction: Int)
Unit
dispatchVisibilityChanged(changedView: View!, visibility: Int)
Unit
Unit
Unit
WindowInsets!
dispatchWindowInsetsAnimationProgress(
    insets: WindowInsets!,
    runningAnimations: (Mutable)List<WindowInsetsAnimation!>!
)
WindowInsetsAnimation.Bounds!
Unit

This function is deprecated.

Unit
Boolean
drawChild(canvas: Canvas!, child: View!, drawingTime: Long)
Unit
View!
OnBackInvokedDispatcher!
Unit
findViewsWithText(
    outViews: ArrayList<View!>!,
    text: CharSequence!,
    flags: Int
)
View!
focusSearch(focused: View!, direction: Int)
Unit
Boolean
CharSequence!
View!
getChildAt(index: Int)
Int
java-static Int
getChildMeasureSpec(spec: Int, padding: Int, childDimension: Int)
Boolean
Boolean
getChildVisibleRect(child: View!, r: Rect!, offset: Point!)
Boolean
Boolean
Int
View!
LayoutAnimationController!
Animation.AnimationListener!
Int
LayoutTransition!
Int
ViewGroupOverlay!
Int

This function is deprecated.

Boolean
Boolean
Boolean
Int
indexOfChild(child: View!)
Unit
invalidateChild(child: View!, dirty: Rect!)

This function is deprecated.

ViewParent!
invalidateChildInParent(location: IntArray!, dirty: Rect!)

This function is deprecated.

Boolean

This function is deprecated.

Boolean

This function is deprecated.

Boolean
Boolean

This function is deprecated.

Boolean
Boolean
Boolean
Unit
Unit
layout(l: Int, t: Int, r: Int, b: Int)
Unit
measureChild(
    child: View!,
    parentWidthMeasureSpec: Int,
    parentHeightMeasureSpec: Int
)
Unit
measureChildWithMargins(
    child: View!,
    parentWidthMeasureSpec: Int,
    widthUsed: Int,
    parentHeightMeasureSpec: Int,
    heightUsed: Int
)
Unit
measureChildren(widthMeasureSpec: Int, heightMeasureSpec: Int)
Unit
notifySubtreeAccessibilityStateChanged(
    child: View!,
    source: View!,
    changeType: Int
)
Unit
offsetDescendantRectToMyCoords(descendant: View!, rect: Rect!)
Unit
offsetRectIntoDescendantCoords(descendant: View!, rect: Rect!)
IntArray<Int>!
Unit
onDescendantInvalidated(child: View!, target: View!)
Boolean
Boolean
onNestedFling(
    target: View!,
    velocityX: Float,
    velocityY: Float,
    consumed: Boolean
)
Boolean
onNestedPreFling(target: View!, velocityX: Float, velocityY: Float)
Boolean
onNestedPrePerformAccessibilityAction(
    target: View!,
    action: Int,
    args: Bundle!
)
Unit
onNestedPreScroll(target: View!, dx: Int, dy: Int, consumed: IntArray!)
Unit
onNestedScroll(
    target: View!,
    dxConsumed: Int,
    dyConsumed: Int,
    dxUnconsumed: Int,
    dyUnconsumed: Int
)
Unit
onNestedScrollAccepted(child: View!, target: View!, axes: Int)
Boolean
PointerIcon!
onResolvePointerIcon(event: MotionEvent!, pointerIndex: Int)
Boolean
onStartNestedScroll(child: View!, target: View!, nestedScrollAxes: Int)
Unit
Unit
onViewAdded(child: View!)
Unit
Unit
Unit
Unit
Unit
removeDetachedView(child: View!, animate: Boolean)
Unit
removeViewAt(index: Int)
Unit
Unit
removeViews(start: Int, count: Int)
Unit
removeViewsInLayout(start: Int, count: Int)
Unit
requestChildFocus(child: View!, focused: View!)
Boolean
requestChildRectangleOnScreen(
    child: View!,
    rectangle: Rect!,
    immediate: Boolean
)
Unit
Boolean
requestFocus(direction: Int, previouslyFocusedRect: Rect!)
Boolean
Unit
Boolean
Unit
Unit
Unit

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit
Unit

This function is deprecated.

Unit
setClipChildren(clipChildren: Boolean)
Unit
setClipToPadding(clipToPadding: Boolean)
Unit
Unit
Unit
Unit
setLayoutMode(layoutMode: Int)
Unit
Unit
Unit
Unit
setPersistentDrawingCache(drawingCacheToKeep: Int)

This function is deprecated.

Unit
Unit
setTouchscreenBlocksFocus(touchscreenBlocksFocus: Boolean)
Unit
setTransitionGroup(isTransitionGroup: Boolean)
Unit
Boolean
Boolean
showContextMenuForChild(originalView: View!)
ActionMode!
startActionModeForChild(
    originalView: View!,
    callback: ActionMode.Callback!
)
Unit
Unit
Unit
Unit

Constants

SCROLL_STATE_DRAGGING

Added in 1.1.0-rc01
const val SCROLL_STATE_DRAGGING = 1: Int

Indicates that the pager is currently being dragged by the user.

SCROLL_STATE_IDLE

Added in 1.1.0-rc01
const val SCROLL_STATE_IDLE = 0: Int

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

Added in 1.1.0-rc01
const val SCROLL_STATE_SETTLING = 2: Int

Indicates that the pager is in the process of settling to a final position.

Public constructors

ViewPager

Added in 1.1.0-rc01
ViewPager(context: Context)

ViewPager

Added in 1.1.0-rc01
ViewPager(context: Context, attrs: AttributeSet?)

Public functions

addFocusables

fun addFocusables(views: ArrayList<View!>!, direction: Int, focusableMode: Int): Unit

We only want the current page that is being shown to be focusable.

addOnAdapterChangeListener

Added in 1.1.0-rc01
fun addOnAdapterChangeListener(listener: ViewPager.OnAdapterChangeListener): Unit

Add a listener that will be invoked whenever the adapter for this ViewPager changes.

Parameters
listener: ViewPager.OnAdapterChangeListener

listener to add

addOnPageChangeListener

Added in 1.1.0-rc01
fun addOnPageChangeListener(listener: ViewPager.OnPageChangeListener): Unit

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
listener: ViewPager.OnPageChangeListener

listener to add

addTouchables

fun addTouchables(views: ArrayList<View!>!): Unit

We only want the current page that is being shown to be touchable.

addView

fun addView(child: View!, index: Int, params: ViewGroup.LayoutParams!): Unit

arrowScroll

Added in 1.1.0-rc01
fun arrowScroll(direction: Int): Boolean

Handle scrolling in response to a left or right arrow click.

Parameters
direction: Int

The direction corresponding to the arrow key that was pressed. It should be either FOCUS_LEFT or FOCUS_RIGHT.

Returns
Boolean

Whether the scrolling was handled successfully.

beginFakeDrag

Added in 1.1.0-rc01
fun beginFakeDrag(): Boolean

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.

canScrollHorizontally

fun canScrollHorizontally(direction: Int): Boolean

Check if this ViewPager can be scrolled horizontally in a certain direction.

Parameters
direction: Int

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

Added in 1.1.0-rc01
fun clearOnPageChangeListeners(): Unit

Remove all listeners that are notified of any changes in scroll state or position.

computeScroll

fun computeScroll(): Unit

dispatchKeyEvent

fun dispatchKeyEvent(event: KeyEvent!): Boolean

dispatchPopulateAccessibilityEvent

fun dispatchPopulateAccessibilityEvent(event: AccessibilityEvent!): Boolean

draw

fun draw(canvas: Canvas): Unit

endFakeDrag

Added in 1.1.0-rc01
fun endFakeDrag(): Unit

End a fake drag of the pager.

executeKeyEvent

Added in 1.1.0-rc01
fun executeKeyEvent(event: KeyEvent): Boolean

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.

Parameters
event: KeyEvent

The key event to execute.

Returns
Boolean

Return true if the event was handled, else false.

fakeDragBy

Added in 1.1.0-rc01
fun fakeDragBy(xOffset: Float): Unit

Fake drag by an offset in pixels. You must have called beginFakeDrag first.

Parameters
xOffset: Float

Offset in pixels to drag by.

generateLayoutParams

fun generateLayoutParams(attrs: AttributeSet!): ViewGroup.LayoutParams!

getAdapter

Added in 1.1.0-rc01
fun getAdapter(): PagerAdapter?

Retrieve the current adapter supplying pages.

Returns
PagerAdapter?

The currently registered PagerAdapter

getCurrentItem

Added in 1.1.0-rc01
fun getCurrentItem(): Int

getOffscreenPageLimit

Added in 1.1.0-rc01
fun getOffscreenPageLimit(): 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. Defaults to 1.

Returns
Int

How many pages will be kept offscreen on either side

getPageMargin

Added in 1.1.0-rc01
fun getPageMargin(): Int

Return the margin between pages.

Returns
Int

The size of the margin in pixels

isDragInGutterEnabled

Added in 1.1.0-rc01
fun isDragInGutterEnabled(): Boolean
Returns
Boolean

Whether dragging in the gutter (left and right edges) of the ViewPager is enabled.

isFakeDragging

Added in 1.1.0-rc01
fun isFakeDragging(): Boolean

Returns true if a fake drag is in progress.

Returns
Boolean

true if currently in a fake drag, false otherwise.

onInterceptTouchEvent

fun onInterceptTouchEvent(ev: MotionEvent!): Boolean

onRestoreInstanceState

Added in 1.1.0-rc01
fun onRestoreInstanceState(state: Parcelable!): Unit

onSaveInstanceState

Added in 1.1.0-rc01
fun onSaveInstanceState(): Parcelable

onTouchEvent

fun onTouchEvent(ev: MotionEvent!): Boolean

removeOnAdapterChangeListener

Added in 1.1.0-rc01
fun removeOnAdapterChangeListener(
    listener: ViewPager.OnAdapterChangeListener
): Unit

Remove a listener that was previously added via addOnAdapterChangeListener.

Parameters
listener: ViewPager.OnAdapterChangeListener

listener to remove

removeOnPageChangeListener

Added in 1.1.0-rc01
fun removeOnPageChangeListener(listener: ViewPager.OnPageChangeListener): Unit

Remove a listener that was previously added via addOnPageChangeListener.

Parameters
listener: ViewPager.OnPageChangeListener

listener to remove

removeView

fun removeView(view: View!): Unit

setAdapter

Added in 1.1.0-rc01
fun setAdapter(adapter: PagerAdapter?): Unit

Set a PagerAdapter that will supply views for this pager as needed.

Parameters
adapter: PagerAdapter?

Adapter to use

setCurrentItem

Added in 1.1.0-rc01
fun setCurrentItem(item: Int): Unit

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
item: Int

Item index to select

setCurrentItem

Added in 1.1.0-rc01
fun setCurrentItem(item: Int, smoothScroll: Boolean): Unit

Set the currently selected page.

Parameters
item: Int

Item index to select

smoothScroll: Boolean

True to smoothly scroll to the new item, false to transition immediately

setDragInGutterEnabled

Added in 1.1.0-rc01
fun setDragInGutterEnabled(enabled: Boolean): Unit

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
enabled: Boolean

true if ViewPager should allow drag in gutter, false otherwise

setOffscreenPageLimit

Added in 1.1.0-rc01
fun setOffscreenPageLimit(limit: Int): Unit

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
limit: Int

How many pages will be kept offscreen in an idle state.

setOnPageChangeListener

Added in 1.1.0-rc01
Deprecated in 1.1.0-rc01
fun setOnPageChangeListener(listener: ViewPager.OnPageChangeListener!): Unit

Set a listener that will be invoked whenever the page changes or is incrementally scrolled. See OnPageChangeListener.

Parameters
listener: ViewPager.OnPageChangeListener!

Listener to set

setPageMargin

Added in 1.1.0-rc01
fun setPageMargin(marginPixels: Int): Unit

Set the margin between pages.

Parameters
marginPixels: Int

Distance between adjacent pages in pixels

setPageMarginDrawable

Added in 1.1.0-rc01
fun setPageMarginDrawable(d: Drawable?): Unit

Set a drawable that will be used to fill the margin between pages.

Parameters
d: Drawable?

Drawable to display between pages

setPageMarginDrawable

Added in 1.1.0-rc01
fun setPageMarginDrawable(resId: @DrawableRes Int): Unit

Set a drawable that will be used to fill the margin between pages.

Parameters
resId: @DrawableRes Int

Resource ID of a drawable to display between pages

setPageTransformer

Added in 1.1.0-rc01
fun setPageTransformer(
    reverseDrawingOrder: Boolean,
    transformer: ViewPager.PageTransformer?
): Unit

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
reverseDrawingOrder: Boolean

true if the supplied PageTransformer requires page views to be drawn from last to first instead of first to last.

transformer: ViewPager.PageTransformer?

PageTransformer that will modify each page's animation properties

setPageTransformer

Added in 1.1.0-rc01
fun setPageTransformer(
    reverseDrawingOrder: Boolean,
    transformer: ViewPager.PageTransformer?,
    pageLayerType: Int
): Unit

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
reverseDrawingOrder: Boolean

true if the supplied PageTransformer requires page views to be drawn from last to first instead of first to last.

transformer: ViewPager.PageTransformer?

PageTransformer that will modify each page's animation properties

pageLayerType: Int

View layer type that should be used for ViewPager pages. It should be either LAYER_TYPE_HARDWARE, LAYER_TYPE_SOFTWARE, or LAYER_TYPE_NONE.

Protected functions

canScroll

Added in 1.1.0-rc01
protected fun canScroll(v: View, checkV: Boolean, dx: Int, x: Int, y: Int): Boolean

Tests scrollability within child views of v given a delta of dx.

Parameters
v: View

View to test for horizontal scrollability

checkV: Boolean

Whether the view v passed should itself be checked for scrollability (true), or just its children (false).

dx: Int

Delta scrolled in pixels

x: Int

X coordinate of the active touch point

y: Int

Y coordinate of the active touch point

Returns
Boolean

true if child views of v can be scrolled by delta of dx.

checkLayoutParams

protected fun checkLayoutParams(p: ViewGroup.LayoutParams!): Boolean

drawableStateChanged

protected fun drawableStateChanged(): Unit

generateDefaultLayoutParams

protected fun generateDefaultLayoutParams(): ViewGroup.LayoutParams!

generateLayoutParams

protected fun generateLayoutParams(p: ViewGroup.LayoutParams!): ViewGroup.LayoutParams!

getChildDrawingOrder

protected fun getChildDrawingOrder(childCount: Int, i: Int): Int

onAttachedToWindow

protected fun onAttachedToWindow(): Unit

onDetachedFromWindow

protected fun onDetachedFromWindow(): Unit

onDraw

protected fun onDraw(canvas: Canvas): Unit

onLayout

protected fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int): Unit

onMeasure

protected fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int): Unit

onPageScrolled

Added in 1.1.0-rc01
@CallSuper
protected fun onPageScrolled(position: Int, offset: Float, offsetPixels: Int): Unit

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
position: Int

Position index of the first page currently being displayed. Page position+1 will be visible if positionOffset is nonzero.

offset: Float

Value from [0, 1) indicating the offset from the page at position.

offsetPixels: Int

Value in pixels indicating the offset from position.

onRequestFocusInDescendants

protected fun onRequestFocusInDescendants(direction: Int, previouslyFocusedRect: Rect!): Boolean

We only want the current page that is being shown to be focusable.

onSizeChanged

protected fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int): Unit

verifyDrawable

protected fun verifyDrawable(who: Drawable): Boolean