public class ViewPager extends ViewGroup
PagerAdapter
to generate the pages that the view shows.
Note this class is currently under early design and development. The API will likely change in later updates of the compatibility library, requiring changes to the source code of apps when they are compiled against the newer version.
ViewPager is most often used in conjunction with 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
FragmentPagerAdapter
,
FragmentStatePagerAdapter
,
FragmentPagerAdapter
, and
FragmentStatePagerAdapter
; each of these
classes have simple code showing how to build a full user interface
with them.
Here is a more complicated example of ViewPager, using it in conjuction
with ActionBar
tabs. You can find other examples of using
ViewPager in the API 4+ Support Demos and API 13+ Support Demos sample code.
Modifier and Type | Class and Description |
---|---|
static class |
ViewPager.LayoutParams
Layout parameters that should be supplied for views added to a
ViewPager.
|
static interface |
ViewPager.OnPageChangeListener
Callback interface for responding to changing state of the selected page.
|
static interface |
ViewPager.PageTransformer
A PageTransformer is invoked whenever a visible/attached page is scrolled.
|
static class |
ViewPager.SavedState
This is the persistent state that is saved by ViewPager.
|
static class |
ViewPager.SimpleOnPageChangeListener
Simple implementation of the
ViewPager.OnPageChangeListener interface with stub
implementations of each method. |
ViewGroup.MarginLayoutParams, ViewGroup.OnHierarchyChangeListener
View.AccessibilityDelegate, View.BaseSavedState, View.DragShadowBuilder, View.MeasureSpec, View.OnAttachStateChangeListener, View.OnClickListener, View.OnCreateContextMenuListener, View.OnDragListener, View.OnFocusChangeListener, View.OnGenericMotionListener, View.OnHoverListener, View.OnKeyListener, View.OnLayoutChangeListener, View.OnLongClickListener, View.OnSystemUiVisibilityChangeListener, View.OnTouchListener
Modifier and Type | Field and Description |
---|---|
static int |
SCROLL_STATE_DRAGGING
Indicates that the pager is currently being dragged by the user.
|
static int |
SCROLL_STATE_IDLE
Indicates that the pager is in an idle, settled state.
|
static int |
SCROLL_STATE_SETTLING
Indicates that the pager is in the process of settling to a final position.
|
CLIP_BOUNDS, CLIP_TO_PADDING_MASK, FLAG_DISALLOW_INTERCEPT, FLAG_SUPPORT_STATIC_TRANSFORMATIONS, FLAG_USE_CHILD_DRAWING_ORDER, FOCUS_AFTER_DESCENDANTS, FOCUS_BEFORE_DESCENDANTS, FOCUS_BLOCK_DESCENDANTS, mDisappearingChildren, mGroupFlags, mOnHierarchyChangeListener, mPersistentDrawingCache, OPTICAL_BOUNDS, PERSISTENT_ALL_CACHES, PERSISTENT_ANIMATION_CACHE, PERSISTENT_NO_CACHE, PERSISTENT_SCROLLING_CACHE
ALPHA, DEBUG_LAYOUT_PROPERTY, DRAG_FLAG_GLOBAL, DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_HIGH, DRAWING_CACHE_QUALITY_LOW, EMPTY_STATE_SET, ENABLED_FOCUSED_SELECTED_STATE_SET, ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_FOCUSED_STATE_SET, ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, ENABLED_SELECTED_STATE_SET, ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_STATE_SET, ENABLED_WINDOW_FOCUSED_STATE_SET, FIND_VIEWS_WITH_ACCESSIBILITY_NODE_PROVIDERS, FIND_VIEWS_WITH_CONTENT_DESCRIPTION, FIND_VIEWS_WITH_TEXT, FOCUS_BACKWARD, FOCUS_DOWN, FOCUS_FORWARD, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_UP, FOCUSABLES_ALL, FOCUSABLES_TOUCH_MODE, FOCUSED_SELECTED_STATE_SET, FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, FOCUSED_STATE_SET, FOCUSED_WINDOW_FOCUSED_STATE_SET, GONE, HAPTIC_FEEDBACK_ENABLED, IMPORTANT_FOR_ACCESSIBILITY_AUTO, IMPORTANT_FOR_ACCESSIBILITY_NO, IMPORTANT_FOR_ACCESSIBILITY_YES, INVISIBLE, KEEP_SCREEN_ON, LAYER_TYPE_HARDWARE, LAYER_TYPE_NONE, LAYER_TYPE_SOFTWARE, LAYOUT_DIRECTION_INHERIT, LAYOUT_DIRECTION_LOCALE, LAYOUT_DIRECTION_LTR, LAYOUT_DIRECTION_RTL, mBottom, mCachingFailed, mContext, mCurrentAnimation, MEASURED_HEIGHT_STATE_SHIFT, MEASURED_SIZE_MASK, MEASURED_STATE_MASK, MEASURED_STATE_TOO_SMALL, mInputEventConsistencyVerifier, mLayoutParams, mLeft, mPaddingBottom, mPaddingLeft, mPaddingRight, mPaddingTop, mParent, mRight, mScrollX, mScrollY, mTag, mTop, mUserPaddingBottom, mUserPaddingLeft, mUserPaddingRight, NO_ID, OVER_SCROLL_ALWAYS, OVER_SCROLL_IF_CONTENT_SCROLLS, OVER_SCROLL_NEVER, PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET, PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_SELECTED_STATE_SET, PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_STATE_SET, PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_SELECTED_STATE_SET, PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_STATE_SET, PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_SELECTED_STATE_SET, PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_STATE_SET, PRESSED_WINDOW_FOCUSED_STATE_SET, PUBLIC_STATUS_BAR_VISIBILITY_MASK, ROTATION, ROTATION_X, ROTATION_Y, SCALE_X, SCALE_Y, SCREEN_STATE_OFF, SCREEN_STATE_ON, SCROLLBAR_POSITION_DEFAULT, SCROLLBAR_POSITION_LEFT, SCROLLBAR_POSITION_RIGHT, SCROLLBARS_INSIDE_INSET, SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_OUTSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY, SELECTED_STATE_SET, SELECTED_WINDOW_FOCUSED_STATE_SET, SOUND_EFFECTS_ENABLED, STATUS_BAR_DISABLE_BACK, STATUS_BAR_DISABLE_CLOCK, STATUS_BAR_DISABLE_EXPAND, STATUS_BAR_DISABLE_HOME, STATUS_BAR_DISABLE_NOTIFICATION_ALERTS, STATUS_BAR_DISABLE_NOTIFICATION_ICONS, STATUS_BAR_DISABLE_NOTIFICATION_TICKER, STATUS_BAR_DISABLE_RECENT, STATUS_BAR_DISABLE_SEARCH, STATUS_BAR_DISABLE_SYSTEM_INFO, STATUS_BAR_HIDDEN, STATUS_BAR_VISIBLE, SYSTEM_UI_CLEARABLE_FLAGS, SYSTEM_UI_FLAG_FULLSCREEN, SYSTEM_UI_FLAG_HIDE_NAVIGATION, SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN, SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION, SYSTEM_UI_FLAG_LAYOUT_STABLE, SYSTEM_UI_FLAG_LOW_PROFILE, SYSTEM_UI_FLAG_VISIBLE, SYSTEM_UI_LAYOUT_FLAGS, TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_GRAVITY, TEXT_ALIGNMENT_INHERIT, TEXT_ALIGNMENT_TEXT_END, TEXT_ALIGNMENT_TEXT_START, TEXT_ALIGNMENT_VIEW_END, TEXT_ALIGNMENT_VIEW_START, TEXT_DIRECTION_ANY_RTL, TEXT_DIRECTION_FIRST_STRONG, TEXT_DIRECTION_INHERIT, TEXT_DIRECTION_LOCALE, TEXT_DIRECTION_LTR, TEXT_DIRECTION_RTL, TRANSLATION_X, TRANSLATION_Y, VIEW_LOG_TAG, VISIBLE, WINDOW_FOCUSED_STATE_SET, X, Y
Constructor and Description |
---|
ViewPager(Context context) |
ViewPager(Context context,
AttributeSet attrs) |
Modifier and Type | Method and Description |
---|---|
void |
addFocusables(ArrayList<View> views,
int direction,
int focusableMode)
We only want the current page that is being shown to be focusable.
|
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)
Adds a child view with the specified layout parameters.
|
boolean |
arrowScroll(int direction) |
boolean |
beginFakeDrag()
Start a fake drag of the pager.
|
protected boolean |
canScroll(View v,
boolean checkV,
int dx,
int x,
int y)
Tests scrollability within child views of v given a delta of dx.
|
protected boolean |
checkLayoutParams(ViewGroup.LayoutParams p) |
void |
computeScroll()
Called by a parent to request that a child update its values for mScrollX
and mScrollY if necessary.
|
boolean |
dispatchKeyEvent(KeyEvent event)
Dispatch a key event to the next view on the focus path.
|
boolean |
dispatchPopulateAccessibilityEvent(AccessibilityEvent event)
Dispatches an
AccessibilityEvent to the View first and then
to its children for adding their text content to the event. |
void |
draw(Canvas canvas)
Manually render this view (and all of its children) to the given Canvas.
|
protected void |
drawableStateChanged()
This function is called whenever the state of the view changes in such
a way that it impacts the state of drawables being shown.
|
void |
endFakeDrag()
End a fake drag of the pager.
|
boolean |
executeKeyEvent(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.
|
protected ViewGroup.LayoutParams |
generateDefaultLayoutParams()
Returns a set of default layout parameters.
|
ViewGroup.LayoutParams |
generateLayoutParams(AttributeSet attrs)
Returns a new set of layout parameters based on the supplied attributes set.
|
protected ViewGroup.LayoutParams |
generateLayoutParams(ViewGroup.LayoutParams p)
Returns a safe set of layout parameters based on the supplied layout params.
|
PagerAdapter |
getAdapter()
Retrieve the current adapter supplying pages.
|
protected int |
getChildDrawingOrder(int childCount,
int i)
Returns the index of the child to draw for this iteration.
|
int |
getCurrentItem() |
int |
getOffscreenPageLimit()
Returns the number of pages that will be retained to either side of the
current page in the view hierarchy in an idle state.
|
int |
getPageMargin()
Return the margin between pages.
|
boolean |
isFakeDragging()
Returns true if a fake drag is in progress.
|
protected void |
onAttachedToWindow()
This is called when the view is attached to a window.
|
protected void |
onDetachedFromWindow()
This is called when the view is detached from a window.
|
protected void |
onDraw(Canvas canvas)
Implement this to do your drawing.
|
boolean |
onInterceptTouchEvent(MotionEvent ev)
Implement this method to intercept all touch screen motion events.
|
protected void |
onLayout(boolean changed,
int l,
int t,
int r,
int b)
Called from layout when this view should
assign a size and position to each of its children.
|
protected void |
onMeasure(int widthMeasureSpec,
int heightMeasureSpec)
Measure the view and its content to determine the measured width and the
measured height.
|
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.
|
protected boolean |
onRequestFocusInDescendants(int direction,
Rect previouslyFocusedRect)
We only want the current page that is being shown to be focusable.
|
void |
onRestoreInstanceState(Parcelable state)
Hook allowing a view to re-apply a representation of its internal state that had previously
been generated by
View.onSaveInstanceState() . |
Parcelable |
onSaveInstanceState()
Hook allowing a view to generate a representation of its internal state
that can later be used to create a new instance with that same state.
|
protected void |
onSizeChanged(int w,
int h,
int oldw,
int oldh)
This is called during layout when the size of this view has changed.
|
boolean |
onTouchEvent(MotionEvent ev)
Implement this method to handle touch screen motion events.
|
void |
setAdapter(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 |
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 |
setOnPageChangeListener(ViewPager.OnPageChangeListener listener)
Set a listener that will be invoked whenever the page changes or is incrementally
scrolled.
|
void |
setPageMargin(int marginPixels)
Set the margin between pages.
|
void |
setPageMarginDrawable(Drawable d)
Set a drawable that will be used to fill the margin between pages.
|
void |
setPageMarginDrawable(int resId)
Set a drawable that will be used to fill the margin between pages.
|
void |
setPageTransformer(boolean reverseDrawingOrder,
ViewPager.PageTransformer transformer)
Set a
ViewPager.PageTransformer that will be called for each attached page whenever
the scroll position is changed. |
protected boolean |
verifyDrawable(Drawable who)
If your view subclass is displaying its own Drawable objects, it should
override this function and return true for any Drawable it is
displaying.
|
addChildrenForAccessibility, addStatesFromChildren, addView, addView, addView, addView, addViewInLayout, addViewInLayout, attachLayoutAnimationParameters, attachViewToParent, bringChildToFront, canAnimate, childAccessibilityStateChanged, childDrawableStateChanged, childHasTransientStateChanged, cleanupLayoutState, clearChildFocus, clearDisappearingChildren, clearFocus, debug, detachAllViewsFromParent, detachViewFromParent, detachViewFromParent, detachViewsFromParent, dispatchConfigurationChanged, dispatchDisplayHint, dispatchDragEvent, dispatchDraw, dispatchFinishTemporaryDetach, dispatchFreezeSelfOnly, dispatchGenericFocusedEvent, dispatchGenericPointerEvent, dispatchGetDisplayList, dispatchHoverEvent, dispatchKeyEventPreIme, dispatchKeyShortcutEvent, dispatchRestoreInstanceState, dispatchSaveInstanceState, dispatchSetActivated, dispatchSetPressed, dispatchSetSelected, dispatchStartTemporaryDetach, dispatchSystemUiVisibilityChanged, dispatchThawSelfOnly, dispatchTouchEvent, dispatchTrackballEvent, dispatchUnhandledMove, dispatchVisibilityChanged, dispatchWindowFocusChanged, dispatchWindowSystemUiVisiblityChanged, dispatchWindowVisibilityChanged, drawChild, endViewTransition, findFocus, findViewByPredicateTraversal, findViewsWithText, findViewTraversal, findViewWithTagTraversal, fitSystemWindows, focusableViewAvailable, focusSearch, gatherTransparentRegion, getChildAt, getChildCount, getChildMeasureSpec, getChildStaticTransformation, getChildVisibleRect, getDescendantFocusability, getFocusedChild, getLayoutAnimation, getLayoutAnimationListener, getLayoutMode, getLayoutTransition, getPersistentDrawingCache, hasFocus, hasFocusable, hasHoveredChild, hasTransientState, indexOfChild, internalSetPadding, invalidateChild, invalidateChildFast, invalidateChildInParent, isAlwaysDrawnWithCacheEnabled, isAnimationCacheEnabled, isChildrenDrawingOrderEnabled, isChildrenDrawnWithCacheEnabled, isMotionEventSplittingEnabled, isTransformedTouchPointInView, jumpDrawablesToCurrentState, layout, makeOptionalFitsSystemWindows, measureChild, measureChildren, measureChildWithMargins, offsetChildrenTopAndBottom, offsetDescendantRectToMyCoords, offsetRectIntoDescendantCoords, onAnimationEnd, onAnimationStart, onChildVisibilityChanged, onCreateDrawableState, onDebugDraw, onDebugDrawMargins, onInterceptHoverEvent, onRequestSendAccessibilityEvent, onSetLayoutParams, onViewAdded, onViewRemoved, recomputeViewAttributes, removeAllViews, removeAllViewsInLayout, removeDetachedView, removeView, removeViewAt, removeViewInLayout, removeViews, removeViewsInLayout, requestChildFocus, requestChildRectangleOnScreen, requestDisallowInterceptTouchEvent, requestFocus, requestSendAccessibilityEvent, requestTransitionStart, requestTransparentRegion, resetAccessibilityStateChanged, resetResolvedDrawables, resetResolvedLayoutDirection, resetResolvedPadding, resetResolvedTextAlignment, resetResolvedTextDirection, resetRtlProperties, resolveDrawables, resolveLayoutDirection, resolveLayoutParams, resolvePadding, resolveRtlPropertiesIfNeeded, resolveTextAlignment, resolveTextDirection, scheduleLayoutAnimation, setAddStatesFromChildren, setAlwaysDrawnWithCacheEnabled, setAnimationCacheEnabled, setChildrenDrawingCacheEnabled, setChildrenDrawingOrderEnabled, setChildrenDrawnWithCacheEnabled, setClipChildren, setClipToPadding, setDescendantFocusability, setLayoutAnimation, setLayoutAnimationListener, setLayoutMode, setLayoutTransition, setMotionEventSplittingEnabled, setOnHierarchyChangeListener, setPersistentDrawingCache, setStaticTransformationsEnabled, shouldDelayChildPressedState, showContextMenuForChild, startActionModeForChild, startLayoutAnimation, startViewTransition, updateViewLayout
addFocusables, addOnAttachStateChangeListener, addOnLayoutChangeListener, animate, announceForAccessibility, applyDrawableToTransparentRegion, awakenScrollBars, awakenScrollBars, awakenScrollBars, bringToFront, buildDrawingCache, buildDrawingCache, buildLayer, callOnClick, cancelLongPress, canHaveDisplayList, canResolveLayoutDirection, canScrollHorizontally, canScrollVertically, checkInputConnectionProxy, clearAccessibilityFocus, clearAnimation, combineMeasuredStates, computeHorizontalScrollExtent, computeHorizontalScrollOffset, computeHorizontalScrollRange, computeOpaqueFlags, computeVerticalScrollExtent, computeVerticalScrollOffset, computeVerticalScrollRange, createAccessibilityNodeInfo, createContextMenu, debug, debugIndent, destroyDrawingCache, destroyHardwareResources, dispatchGenericMotionEvent, dispatchPointerEvent, findViewById, findViewByPredicate, findViewByPredicateInsideOut, findViewWithTag, fitsSystemWindows, focusSearch, forceLayout, generateViewId, getAccessibilityCursorPosition, getAccessibilityDelegate, getAccessibilityNodeProvider, getAccessibilityViewId, getAccessibilityWindowId, getAlpha, getAnimation, getApplicationWindowToken, getBackground, getBaseline, getBottom, getBottomFadingEdgeStrength, getBottomPaddingOffset, getCameraDistance, getContentDescription, getContext, getContextMenuInfo, getDefaultSize, getDisplay, getDisplayList, getDrawableState, getDrawingCache, getDrawingCache, getDrawingCacheBackgroundColor, getDrawingCacheQuality, getDrawingRect, getDrawingTime, getFadeHeight, getFadeTop, getFilterTouchesWhenObscured, getFitsSystemWindows, getFocusables, getFocusedRect, getGlobalVisibleRect, getGlobalVisibleRect, getHandler, getHardwareRenderer, getHeight, getHitRect, getHorizontalFadingEdgeLength, getHorizontalScrollbarHeight, getHorizontalScrollFactor, getId, getImportantForAccessibility, getIterableTextForAccessibility, getIteratorForGranularity, getKeepScreenOn, getKeyDispatcherState, getLabelFor, getLayerType, getLayoutDirection, getLayoutParams, getLeft, getLeftFadingEdgeStrength, getLeftPaddingOffset, getLocalVisibleRect, getLocationInWindow, getLocationOnScreen, getMatrix, getMeasuredHeight, getMeasuredHeightAndState, getMeasuredState, getMeasuredWidth, getMeasuredWidthAndState, getMinimumHeight, getMinimumWidth, getNextFocusDownId, getNextFocusForwardId, getNextFocusLeftId, getNextFocusRightId, getNextFocusUpId, getOnFocusChangeListener, getOpticalInsets, getOverScrollMode, getPaddingBottom, getPaddingEnd, getPaddingLeft, getPaddingRight, getPaddingStart, getPaddingTop, getParent, getParentForAccessibility, getPivotX, getPivotY, getRawLayoutDirection, getRawTextAlignment, getRawTextDirection, getResources, getRight, getRightFadingEdgeStrength, getRightPaddingOffset, getRootView, getRotation, getRotationX, getRotationY, getScaleX, getScaleY, getScrollBarDefaultDelayBeforeFade, getScrollBarFadeDuration, getScrollBarSize, getScrollBarStyle, getScrollX, getScrollY, getSolidColor, getSuggestedMinimumHeight, getSuggestedMinimumWidth, getSystemUiVisibility, getTag, getTag, getTextAlignment, getTextDirection, getTop, getTopFadingEdgeStrength, getTopPaddingOffset, getTouchables, getTouchDelegate, getTranslationX, getTranslationY, getVerticalFadingEdgeLength, getVerticalScrollbarPosition, getVerticalScrollbarWidth, getVerticalScrollFactor, getViewRootImpl, getViewTreeObserver, getVisibility, getWidth, getWindowAttachCount, getWindowSystemUiVisibility, getWindowToken, getWindowVisibility, getWindowVisibleDisplayFrame, getX, getY, hackTurnOffWindowResizeAnim, hasOnClickListeners, hasOpaqueScrollbars, hasOverlappingRendering, hasWindowFocus, includeForAccessibility, inflate, initializeFadingEdge, initializeScrollbars, invalidate, invalidate, invalidate, invalidateDrawable, invalidateParentCaches, invalidateParentIfNeeded, isActionableForAccessibility, isActivated, isClickable, isDirty, isDrawingCacheEnabled, isDuplicateParentStateEnabled, isEnabled, isFocusable, isFocusableInTouchMode, isFocused, isHapticFeedbackEnabled, isHardwareAccelerated, isHorizontalFadingEdgeEnabled, isHorizontalScrollBarEnabled, isHovered, isImportantForAccessibility, isInEditMode, isInScrollingContainer, isInTouchMode, isLayoutDirectionInherited, isLayoutRequested, isLayoutRtl, isLongClickable, isOpaque, isPaddingOffsetRequired, isPaddingRelative, isPressed, isRootNamespace, isSaveEnabled, isSaveFromParentEnabled, isScrollbarFadingEnabled, isScrollContainer, isSelected, isShown, isSoundEffectsEnabled, isTextAlignmentInherited, isTextDirectionInherited, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, isVerticalScrollBarHidden, isVisibleToUser, isVisibleToUser, measure, mergeDrawableStates, notifyAccessibilityStateChanged, offsetLeftAndRight, offsetTopAndBottom, onCheckIsTextEditor, onCloseSystemDialogs, onConfigurationChanged, onCreateContextMenu, onCreateInputConnection, onDisplayHint, onDragEvent, onDrawHorizontalScrollBar, onDrawScrollBars, onDrawVerticalScrollBar, onFilterTouchEventForSecurity, onFinishInflate, onFinishTemporaryDetach, onFocusChanged, onFocusLost, onGenericMotionEvent, onHoverChanged, onHoverEvent, onInitializeAccessibilityEvent, onInitializeAccessibilityNodeInfo, onKeyDown, onKeyLongPress, onKeyMultiple, onKeyPreIme, onKeyShortcut, onKeyUp, onOverScrolled, onPopulateAccessibilityEvent, onResolveDrawables, onRtlPropertiesChanged, onScreenStateChanged, onScrollChanged, onSetAlpha, onStartTemporaryDetach, onTrackballEvent, onVisibilityChanged, onWindowFocusChanged, onWindowSystemUiVisibilityChanged, onWindowVisibilityChanged, outputDirtyFlags, overScrollBy, performAccessibilityAction, performButtonActionOnTouchDown, performClick, performHapticFeedback, performHapticFeedback, performLongClick, playSoundEffect, post, postDelayed, postInvalidate, postInvalidate, postInvalidateDelayed, postInvalidateDelayed, postInvalidateOnAnimation, postInvalidateOnAnimation, postOnAnimation, postOnAnimationDelayed, recomputePadding, refreshDrawableState, removeCallbacks, removeOnAttachStateChangeListener, removeOnLayoutChangeListener, requestAccessibilityFocus, requestFitSystemWindows, requestFocus, requestFocus, requestFocusFromTouch, requestLayout, requestRectangleOnScreen, requestRectangleOnScreen, resetPaddingToInitialValues, resolveSize, resolveSizeAndState, restoreHierarchyState, saveHierarchyState, scheduleDrawable, scrollBy, scrollTo, sendAccessibilityEvent, sendAccessibilityEventUnchecked, setAccessibilityCursorPosition, setAccessibilityDelegate, setActivated, setAlpha, setAnimation, setBackground, setBackgroundColor, setBackgroundDrawable, setBackgroundResource, setBottom, setCameraDistance, setClickable, setContentDescription, setDisabledSystemUiVisibility, setDrawingCacheBackgroundColor, setDrawingCacheEnabled, setDrawingCacheQuality, setDuplicateParentStateEnabled, setEnabled, setFadingEdgeLength, setFilterTouchesWhenObscured, setFitsSystemWindows, setFocusable, setFocusableInTouchMode, setFrame, setHapticFeedbackEnabled, setHasTransientState, setHorizontalFadingEdgeEnabled, setHorizontalScrollBarEnabled, setHovered, setId, setImportantForAccessibility, setIsRootNamespace, setKeepScreenOn, setLabelFor, setLayerPaint, setLayerType, setLayoutDirection, setLayoutInsets, setLayoutParams, setLeft, setLongClickable, setMeasuredDimension, setMinimumHeight, setMinimumWidth, setNextFocusDownId, setNextFocusForwardId, setNextFocusLeftId, setNextFocusRightId, setNextFocusUpId, setOnClickListener, setOnCreateContextMenuListener, setOnDragListener, setOnFocusChangeListener, setOnGenericMotionListener, setOnHoverListener, setOnKeyListener, setOnLongClickListener, setOnSystemUiVisibilityChangeListener, setOnTouchListener, setOverScrollMode, setPadding, setPaddingRelative, setPivotX, setPivotY, setPressed, setRight, setRotation, setRotationX, setRotationY, setSaveEnabled, setSaveFromParentEnabled, setScaleX, setScaleY, setScrollBarDefaultDelayBeforeFade, setScrollBarFadeDuration, setScrollbarFadingEnabled, setScrollBarSize, setScrollBarStyle, setScrollContainer, setScrollX, setScrollY, setSelected, setSoundEffectsEnabled, setSystemUiVisibility, setTag, setTag, setTagInternal, setTextAlignment, setTextDirection, setTop, setTouchDelegate, setTranslationX, setTranslationY, setVerticalFadingEdgeEnabled, setVerticalScrollBarEnabled, setVerticalScrollbarPosition, setVisibility, setWillNotCacheDrawing, setWillNotDraw, setX, setY, showContextMenu, showContextMenu, startActionMode, startAnimation, startDrag, toString, unscheduleDrawable, unscheduleDrawable, willNotCacheDrawing, willNotDraw
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
createContextMenu, getParent, getParentForAccessibility, isLayoutRequested, requestFitSystemWindows, requestLayout
public static final int SCROLL_STATE_IDLE
public static final int SCROLL_STATE_DRAGGING
public static final int SCROLL_STATE_SETTLING
public ViewPager(Context context)
public ViewPager(Context context, AttributeSet attrs)
protected void onDetachedFromWindow()
View
onDetachedFromWindow
in class View
View.onAttachedToWindow()
public void setAdapter(PagerAdapter adapter)
adapter
- Adapter to usepublic PagerAdapter getAdapter()
public void setCurrentItem(int item)
item
- Item index to selectpublic void setCurrentItem(int item, boolean smoothScroll)
item
- Item index to selectsmoothScroll
- True to smoothly scroll to the new item, false to transition immediatelypublic int getCurrentItem()
public void setOnPageChangeListener(ViewPager.OnPageChangeListener listener)
ViewPager.OnPageChangeListener
.listener
- Listener to setpublic void setPageTransformer(boolean reverseDrawingOrder, ViewPager.PageTransformer transformer)
ViewPager.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 look and feel.
Note: Prior to Android 3.0 the property animation APIs did not exist. As a result, setting a PageTransformer prior to Android 3.0 (API 11) will have no effect.
reverseDrawingOrder
- true if the supplied PageTransformer requires page views
to be drawn from last to first instead of first to last.transformer
- PageTransformer that will modify each page's animation propertiesprotected int getChildDrawingOrder(int childCount, int i)
ViewGroup
NOTE: In order for this method to be called, you must enable child ordering
first by calling ViewGroup.setChildrenDrawingOrderEnabled(boolean)
.
getChildDrawingOrder
in class ViewGroup
i
- The current iteration.ViewGroup.setChildrenDrawingOrderEnabled(boolean)
,
ViewGroup.isChildrenDrawingOrderEnabled()
public int getOffscreenPageLimit()
setOffscreenPageLimit(int)
public void setOffscreenPageLimit(int limit)
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.
limit
- How many pages will be kept offscreen in an idle state.public void setPageMargin(int marginPixels)
marginPixels
- Distance between adjacent pages in pixelsgetPageMargin()
,
setPageMarginDrawable(Drawable)
,
setPageMarginDrawable(int)
public int getPageMargin()
public void setPageMarginDrawable(Drawable d)
d
- Drawable to display between pagespublic void setPageMarginDrawable(int resId)
resId
- Resource ID of a drawable to display between pagesprotected boolean verifyDrawable(Drawable who)
View
Be sure to call through to the super class when overriding this function.
verifyDrawable
in class View
who
- The Drawable to verify. Return true if it is one you are
displaying, else return the result of calling through to the
super class.View.unscheduleDrawable(android.graphics.drawable.Drawable)
,
View.drawableStateChanged()
protected void drawableStateChanged()
View
Be sure to call through to the superclass when overriding this function.
drawableStateChanged
in class ViewGroup
Drawable.setState(int[])
public Parcelable onSaveInstanceState()
View
Some examples of things you may store here: the current cursor position in a text view (but usually not the text itself since that is stored in a content provider or other persistent storage), the currently selected item in a list view.
onSaveInstanceState
in class View
View.onRestoreInstanceState(android.os.Parcelable)
,
View.saveHierarchyState(android.util.SparseArray)
,
View.dispatchSaveInstanceState(android.util.SparseArray)
,
View.setSaveEnabled(boolean)
public void onRestoreInstanceState(Parcelable state)
View
View.onSaveInstanceState()
. This function will never be called with a
null state.onRestoreInstanceState
in class View
state
- The frozen state that had previously been returned by
View.onSaveInstanceState()
.View.onSaveInstanceState()
,
View.restoreHierarchyState(android.util.SparseArray)
,
View.dispatchRestoreInstanceState(android.util.SparseArray)
public void addView(View child, int index, ViewGroup.LayoutParams params)
ViewGroup
Note: do not invoke this method from
View.draw(android.graphics.Canvas)
, View.onDraw(android.graphics.Canvas)
,
ViewGroup.dispatchDraw(android.graphics.Canvas)
or any related method.
protected void onAttachedToWindow()
View
View.onDraw(android.graphics.Canvas)
,
however it may be called any time before the first onDraw -- including
before or after View.onMeasure(int, int)
.onAttachedToWindow
in class View
View.onDetachedFromWindow()
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
View
Measure the view and its content to determine the measured width and the
measured height. This method is invoked by View.measure(int, int)
and
should be overriden by subclasses to provide accurate and efficient
measurement of their contents.
CONTRACT: When overriding this method, you
must call View.setMeasuredDimension(int, int)
to store the
measured width and height of this view. Failure to do so will trigger an
IllegalStateException
, thrown by
View.measure(int, int)
. Calling the superclass'
View.onMeasure(int, int)
is a valid use.
The base class implementation of measure defaults to the background size,
unless a larger size is allowed by the MeasureSpec. Subclasses should
override View.onMeasure(int, int)
to provide better measurements of
their content.
If this method is overridden, it is the subclass's responsibility to make
sure the measured height and width are at least the view's minimum height
and width (View.getSuggestedMinimumHeight()
and
View.getSuggestedMinimumWidth()
).
onMeasure
in class View
widthMeasureSpec
- horizontal space requirements as imposed by the parent.
The requirements are encoded with
View.MeasureSpec
.heightMeasureSpec
- vertical space requirements as imposed by the parent.
The requirements are encoded with
View.MeasureSpec
.View.getMeasuredWidth()
,
View.getMeasuredHeight()
,
View.setMeasuredDimension(int, int)
,
View.getSuggestedMinimumHeight()
,
View.getSuggestedMinimumWidth()
,
View.MeasureSpec.getMode(int)
,
View.MeasureSpec.getSize(int)
protected void onSizeChanged(int w, int h, int oldw, int oldh)
View
onSizeChanged
in class View
w
- Current width of this view.h
- Current height of this view.oldw
- Old width of this view.oldh
- Old height of this view.protected void onLayout(boolean changed, int l, int t, int r, int b)
ViewGroup
public void computeScroll()
View
Scroller
object.computeScroll
in class View
protected void onPageScrolled(int position, float offset, int offsetPixels)
position
- Position index of the first page currently being displayed.
Page position+1 will be visible if positionOffset is nonzero.offset
- Value from [0, 1) indicating the offset from the page at position.offsetPixels
- Value in pixels indicating the offset from position.public boolean onInterceptTouchEvent(MotionEvent ev)
ViewGroup
Using this function takes some care, as it has a fairly complicated
interaction with View.onTouchEvent(MotionEvent)
, and using it requires implementing
that method as well as this one in the correct way. Events will be
received in the following order:
MotionEvent.ACTION_CANCEL
, and all further
events will be delivered to your onTouchEvent() method and no longer
appear here.
onInterceptTouchEvent
in class ViewGroup
ev
- The motion event being dispatched down the hierarchy.public boolean onTouchEvent(MotionEvent ev)
View
onTouchEvent
in class View
ev
- The motion event.public void draw(Canvas canvas)
View
View.onDraw(android.graphics.Canvas)
instead of overriding this method.
If you do need to override this method, call the superclass version.protected void onDraw(Canvas canvas)
View
public boolean beginFakeDrag()
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(float)
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.
fakeDragBy(float)
,
endFakeDrag()
public void endFakeDrag()
beginFakeDrag()
,
fakeDragBy(float)
public void fakeDragBy(float xOffset)
beginFakeDrag()
first.xOffset
- Offset in pixels to drag by.beginFakeDrag()
,
endFakeDrag()
public boolean isFakeDragging()
beginFakeDrag()
,
fakeDragBy(float)
,
endFakeDrag()
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y)
v
- View to test for horizontal scrollabilitycheckV
- Whether the view v passed should itself be checked for scrollability (true),
or just its children (false).dx
- Delta scrolled in pixelsx
- X coordinate of the active touch pointy
- Y coordinate of the active touch pointpublic boolean dispatchKeyEvent(KeyEvent event)
ViewGroup
dispatchKeyEvent
in class ViewGroup
event
- The key event to be dispatched.public boolean executeKeyEvent(KeyEvent event)
event
- The key event to execute.public boolean arrowScroll(int direction)
public void addFocusables(ArrayList<View> views, int direction, int focusableMode)
addFocusables
in class ViewGroup
views
- Focusable views found so far or null if all we are interested is
the number of focusables.direction
- The direction of the focus.focusableMode
- The type of focusables to be added.View.FOCUSABLES_ALL
,
View.FOCUSABLES_TOUCH_MODE
public void addTouchables(ArrayList<View> views)
addTouchables
in class ViewGroup
views
- Touchable views found so farprotected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect)
onRequestFocusInDescendants
in class ViewGroup
direction
- One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHTpreviouslyFocusedRect
- The rectangle (in this View's coordinate system)
to give a finer grained hint about where focus is coming from. May be null
if there is no hint.public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event)
View
AccessibilityEvent
to the View
first and then
to its children for adding their text content to the event. Note that the
event text is populated in a separate dispatch path since we add to the
event not only the text of the source but also the text of all its descendants.
A typical implementation will call
View.onPopulateAccessibilityEvent(AccessibilityEvent)
on the this view
and then call the View.dispatchPopulateAccessibilityEvent(AccessibilityEvent)
on each child. Override this method if custom population of the event text
content is required.
If an View.AccessibilityDelegate
has been specified via calling
View.setAccessibilityDelegate(AccessibilityDelegate)
its
View.AccessibilityDelegate.dispatchPopulateAccessibilityEvent(View, AccessibilityEvent)
is responsible for handling this call.
Note: Accessibility events of certain types are not dispatched for
populating the event text via this method. For details refer to AccessibilityEvent
.
dispatchPopulateAccessibilityEvent
in class View
event
- The event.protected ViewGroup.LayoutParams generateDefaultLayoutParams()
ViewGroup
ViewGroup.addView(View)
has no layout parameters
already set. If null is returned, an exception is thrown from addView.generateDefaultLayoutParams
in class ViewGroup
protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p)
ViewGroup
ViewGroup.checkLayoutParams(android.view.ViewGroup.LayoutParams)
, this method
is invoked. This method should return a new set of layout params suitable for
this ViewGroup, possibly by copying the appropriate attributes from the
specified set of layout params.generateLayoutParams
in class ViewGroup
p
- The layout parameters to convert into a suitable set of layout parameters
for this ViewGroup.ViewGroup.LayoutParams
or one
of its descendantsprotected boolean checkLayoutParams(ViewGroup.LayoutParams p)
ViewGroup
checkLayoutParams
in class ViewGroup
public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs)
ViewGroup
generateLayoutParams
in class ViewGroup
attrs
- the attributes to build the layout parameters fromViewGroup.LayoutParams
or one
of its descendants