android.support.v4.view
Class ViewPager

java.lang.Object
  extended by android.view.View
      extended by android.view.ViewGroup
          extended by android.support.v4.view.ViewPager
All Implemented Interfaces:
android.graphics.drawable.Drawable.Callback, android.view.accessibility.AccessibilityEventSource, android.view.KeyEvent.Callback, android.view.ViewManager, android.view.ViewParent

public class ViewPager
extends android.view.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.

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 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.


Nested Class Summary
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.
 
Nested classes/interfaces inherited from class android.view.ViewGroup
android.view.ViewGroup.MarginLayoutParams, android.view.ViewGroup.OnHierarchyChangeListener
 
Nested classes/interfaces inherited from class android.view.View
android.view.View.AccessibilityDelegate, android.view.View.BaseSavedState, android.view.View.DragShadowBuilder, android.view.View.MeasureSpec, android.view.View.OnAttachStateChangeListener, android.view.View.OnClickListener, android.view.View.OnCreateContextMenuListener, android.view.View.OnDragListener, android.view.View.OnFocusChangeListener, android.view.View.OnGenericMotionListener, android.view.View.OnHoverListener, android.view.View.OnKeyListener, android.view.View.OnLayoutChangeListener, android.view.View.OnLongClickListener, android.view.View.OnSystemUiVisibilityChangeListener, android.view.View.OnTouchListener
 
Field Summary
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.
 
Fields inherited from class android.view.ViewGroup
CLIP_TO_PADDING_MASK, FOCUS_AFTER_DESCENDANTS, FOCUS_BEFORE_DESCENDANTS, FOCUS_BLOCK_DESCENDANTS, PERSISTENT_ALL_CACHES, PERSISTENT_ANIMATION_CACHE, PERSISTENT_NO_CACHE, PERSISTENT_SCROLLING_CACHE
 
Fields inherited from class android.view.View
ALPHA, 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_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, MEASURED_HEIGHT_STATE_SHIFT, MEASURED_SIZE_MASK, MEASURED_STATE_MASK, MEASURED_STATE_TOO_SMALL, 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_WINDOW_FOCUSED_STATE_SET, 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_HIDDEN, STATUS_BAR_VISIBLE, 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 Summary
ViewPager(android.content.Context context)
           
ViewPager(android.content.Context context, android.util.AttributeSet attrs)
           
 
Method Summary
 void addFocusables(ArrayList<android.view.View> views, int direction, int focusableMode)
          We only want the current page that is being shown to be focusable.
 void addTouchables(ArrayList<android.view.View> views)
          We only want the current page that is being shown to be touchable.
 void addView(android.view.View child, int index, android.view.ViewGroup.LayoutParams params)
           
 boolean arrowScroll(int direction)
           
 boolean beginFakeDrag()
          Start a fake drag of the pager.
protected  boolean canScroll(android.view.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(android.view.ViewGroup.LayoutParams p)
           
 void computeScroll()
           
 boolean dispatchKeyEvent(android.view.KeyEvent event)
           
 boolean dispatchPopulateAccessibilityEvent(android.view.accessibility.AccessibilityEvent event)
           
 void draw(android.graphics.Canvas canvas)
           
protected  void drawableStateChanged()
           
 void endFakeDrag()
          End a fake drag of the pager.
 boolean executeKeyEvent(android.view.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  android.view.ViewGroup.LayoutParams generateDefaultLayoutParams()
           
 android.view.ViewGroup.LayoutParams generateLayoutParams(android.util.AttributeSet attrs)
           
protected  android.view.ViewGroup.LayoutParams generateLayoutParams(android.view.ViewGroup.LayoutParams p)
           
 PagerAdapter getAdapter()
          Retrieve the current adapter supplying pages.
protected  int getChildDrawingOrder(int childCount, int i)
           
 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()
           
protected  void onDetachedFromWindow()
           
protected  void onDraw(android.graphics.Canvas canvas)
           
 boolean onInterceptTouchEvent(android.view.MotionEvent ev)
           
protected  void onLayout(boolean changed, int l, int t, int r, int b)
           
protected  void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
           
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, android.graphics.Rect previouslyFocusedRect)
          We only want the current page that is being shown to be focusable.
 void onRestoreInstanceState(android.os.Parcelable state)
           
 android.os.Parcelable onSaveInstanceState()
           
protected  void onSizeChanged(int w, int h, int oldw, int oldh)
           
 boolean onTouchEvent(android.view.MotionEvent ev)
           
 void removeView(android.view.View view)
           
 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(android.graphics.drawable.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(android.graphics.drawable.Drawable who)
           
 
Methods inherited from class android.view.ViewGroup
addChildrenForAccessibility, addStatesFromChildren, addView, addView, addView, addView, addViewInLayout, addViewInLayout, attachLayoutAnimationParameters, attachViewToParent, bringChildToFront, canAnimate, childDrawableStateChanged, cleanupLayoutState, clearChildFocus, clearDisappearingChildren, clearFocus, debug, detachAllViewsFromParent, detachViewFromParent, detachViewFromParent, detachViewsFromParent, dispatchConfigurationChanged, dispatchDisplayHint, dispatchDragEvent, dispatchDraw, dispatchFreezeSelfOnly, dispatchGenericFocusedEvent, dispatchGenericPointerEvent, dispatchHoverEvent, dispatchKeyEventPreIme, dispatchKeyShortcutEvent, dispatchRestoreInstanceState, dispatchSaveInstanceState, dispatchSetActivated, dispatchSetPressed, dispatchSetSelected, dispatchSystemUiVisibilityChanged, dispatchThawSelfOnly, dispatchTouchEvent, dispatchTrackballEvent, dispatchUnhandledMove, dispatchVisibilityChanged, dispatchWindowFocusChanged, dispatchWindowSystemUiVisiblityChanged, dispatchWindowVisibilityChanged, drawChild, endViewTransition, findFocus, findViewsWithText, fitSystemWindows, focusableViewAvailable, focusSearch, gatherTransparentRegion, getChildAt, getChildCount, getChildMeasureSpec, getChildStaticTransformation, getChildVisibleRect, getDescendantFocusability, getFocusedChild, getLayoutAnimation, getLayoutAnimationListener, getLayoutTransition, getPersistentDrawingCache, hasFocus, hasFocusable, indexOfChild, invalidateChild, invalidateChildInParent, isAlwaysDrawnWithCacheEnabled, isAnimationCacheEnabled, isChildrenDrawingOrderEnabled, isChildrenDrawnWithCacheEnabled, isMotionEventSplittingEnabled, jumpDrawablesToCurrentState, layout, measureChild, measureChildren, measureChildWithMargins, offsetDescendantRectToMyCoords, offsetRectIntoDescendantCoords, onAnimationEnd, onAnimationStart, onCreateDrawableState, onInterceptHoverEvent, onRequestSendAccessibilityEvent, recomputeViewAttributes, removeAllViews, removeAllViewsInLayout, removeDetachedView, removeViewAt, removeViewInLayout, removeViews, removeViewsInLayout, requestChildFocus, requestChildRectangleOnScreen, requestDisallowInterceptTouchEvent, requestFocus, requestSendAccessibilityEvent, requestTransparentRegion, scheduleLayoutAnimation, setAddStatesFromChildren, setAlwaysDrawnWithCacheEnabled, setAnimationCacheEnabled, setChildrenDrawingCacheEnabled, setChildrenDrawingOrderEnabled, setChildrenDrawnWithCacheEnabled, setClipChildren, setClipToPadding, setDescendantFocusability, setLayoutAnimation, setLayoutAnimationListener, setLayoutTransition, setMotionEventSplittingEnabled, setOnHierarchyChangeListener, setPersistentDrawingCache, setStaticTransformationsEnabled, shouldDelayChildPressedState, showContextMenuForChild, startActionModeForChild, startLayoutAnimation, startViewTransition, updateViewLayout
 
Methods inherited from class android.view.View
addFocusables, addOnAttachStateChangeListener, addOnLayoutChangeListener, animate, announceForAccessibility, awakenScrollBars, awakenScrollBars, awakenScrollBars, bringToFront, buildDrawingCache, buildDrawingCache, buildLayer, callOnClick, cancelLongPress, canScrollHorizontally, canScrollVertically, checkInputConnectionProxy, clearAnimation, combineMeasuredStates, computeHorizontalScrollExtent, computeHorizontalScrollOffset, computeHorizontalScrollRange, computeVerticalScrollExtent, computeVerticalScrollOffset, computeVerticalScrollRange, createAccessibilityNodeInfo, createContextMenu, destroyDrawingCache, dispatchGenericMotionEvent, findViewById, findViewWithTag, focusSearch, forceLayout, generateViewId, getAccessibilityNodeProvider, getAlpha, getAnimation, getApplicationWindowToken, getBackground, getBaseline, getBottom, getBottomFadingEdgeStrength, getBottomPaddingOffset, getCameraDistance, getContentDescription, getContext, getContextMenuInfo, getDefaultSize, getDisplay, getDrawableState, getDrawingCache, getDrawingCache, getDrawingCacheBackgroundColor, getDrawingCacheQuality, getDrawingRect, getDrawingTime, getFilterTouchesWhenObscured, getFitsSystemWindows, getFocusables, getFocusedRect, getGlobalVisibleRect, getGlobalVisibleRect, getHandler, getHeight, getHitRect, getHorizontalFadingEdgeLength, getHorizontalScrollbarHeight, getId, getImportantForAccessibility, 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, getOverScrollMode, getPaddingBottom, getPaddingEnd, getPaddingLeft, getPaddingRight, getPaddingStart, getPaddingTop, getParent, getParentForAccessibility, getPivotX, getPivotY, 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, getViewTreeObserver, getVisibility, getWidth, getWindowAttachCount, getWindowSystemUiVisibility, getWindowToken, getWindowVisibility, getWindowVisibleDisplayFrame, getX, getY, hasOnClickListeners, hasOverlappingRendering, hasTransientState, hasWindowFocus, inflate, initializeFadingEdge, initializeScrollbars, invalidate, invalidate, invalidate, invalidateDrawable, isActivated, isClickable, isDirty, isDrawingCacheEnabled, isDuplicateParentStateEnabled, isEnabled, isFocusable, isFocusableInTouchMode, isFocused, isHapticFeedbackEnabled, isHardwareAccelerated, isHorizontalFadingEdgeEnabled, isHorizontalScrollBarEnabled, isHovered, isInEditMode, isInTouchMode, isLayoutRequested, isLongClickable, isOpaque, isPaddingOffsetRequired, isPaddingRelative, isPressed, isSaveEnabled, isSaveFromParentEnabled, isScrollbarFadingEnabled, isScrollContainer, isSelected, isShown, isSoundEffectsEnabled, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, measure, mergeDrawableStates, offsetLeftAndRight, offsetTopAndBottom, onCheckIsTextEditor, onConfigurationChanged, onCreateContextMenu, onCreateInputConnection, onDisplayHint, onDragEvent, onDrawScrollBars, onFilterTouchEventForSecurity, onFinishInflate, onFinishTemporaryDetach, onFocusChanged, onGenericMotionEvent, onHoverChanged, onHoverEvent, onInitializeAccessibilityEvent, onInitializeAccessibilityNodeInfo, onKeyDown, onKeyLongPress, onKeyMultiple, onKeyPreIme, onKeyShortcut, onKeyUp, onOverScrolled, onPopulateAccessibilityEvent, onRtlPropertiesChanged, onScreenStateChanged, onScrollChanged, onSetAlpha, onStartTemporaryDetach, onTrackballEvent, onVisibilityChanged, onWindowFocusChanged, onWindowSystemUiVisibilityChanged, onWindowVisibilityChanged, overScrollBy, performAccessibilityAction, performClick, performHapticFeedback, performHapticFeedback, performLongClick, playSoundEffect, post, postDelayed, postInvalidate, postInvalidate, postInvalidateDelayed, postInvalidateDelayed, postInvalidateOnAnimation, postInvalidateOnAnimation, postOnAnimation, postOnAnimationDelayed, refreshDrawableState, removeCallbacks, removeOnAttachStateChangeListener, removeOnLayoutChangeListener, requestFitSystemWindows, requestFocus, requestFocus, requestFocusFromTouch, requestLayout, requestRectangleOnScreen, requestRectangleOnScreen, resolveSize, resolveSizeAndState, restoreHierarchyState, saveHierarchyState, scheduleDrawable, scrollBy, scrollTo, sendAccessibilityEvent, sendAccessibilityEventUnchecked, setAccessibilityDelegate, setActivated, setAlpha, setAnimation, setBackground, setBackgroundColor, setBackgroundDrawable, setBackgroundResource, setBottom, setCameraDistance, setClickable, setContentDescription, setDrawingCacheBackgroundColor, setDrawingCacheEnabled, setDrawingCacheQuality, setDuplicateParentStateEnabled, setEnabled, setFadingEdgeLength, setFilterTouchesWhenObscured, setFitsSystemWindows, setFocusable, setFocusableInTouchMode, setHapticFeedbackEnabled, setHasTransientState, setHorizontalFadingEdgeEnabled, setHorizontalScrollBarEnabled, setHovered, setId, setImportantForAccessibility, setKeepScreenOn, setLabelFor, setLayerPaint, setLayerType, setLayoutDirection, 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, setTextAlignment, setTextDirection, setTop, setTouchDelegate, setTranslationX, setTranslationY, setVerticalFadingEdgeEnabled, setVerticalScrollBarEnabled, setVerticalScrollbarPosition, setVisibility, setWillNotCacheDrawing, setWillNotDraw, setX, setY, showContextMenu, startActionMode, startAnimation, startDrag, toString, unscheduleDrawable, unscheduleDrawable, willNotCacheDrawing, willNotDraw
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface android.view.ViewParent
createContextMenu, getParent, getParentForAccessibility, isLayoutRequested, requestFitSystemWindows, requestLayout
 

Field Detail

SCROLL_STATE_IDLE

public static final int SCROLL_STATE_IDLE
Indicates that the pager is in an idle, settled state. The current page is fully in view and no animation is in progress.

See Also:
Constant Field Values

SCROLL_STATE_DRAGGING

public static final int SCROLL_STATE_DRAGGING
Indicates that the pager is currently being dragged by the user.

See Also:
Constant Field Values

SCROLL_STATE_SETTLING

public static final int SCROLL_STATE_SETTLING
Indicates that the pager is in the process of settling to a final position.

See Also:
Constant Field Values
Constructor Detail

ViewPager

public ViewPager(android.content.Context context)

ViewPager

public ViewPager(android.content.Context context,
                 android.util.AttributeSet attrs)
Method Detail

onDetachedFromWindow

protected void onDetachedFromWindow()
Overrides:
onDetachedFromWindow in class android.view.View

setAdapter

public void setAdapter(PagerAdapter adapter)
Set a PagerAdapter that will supply views for this pager as needed.

Parameters:
adapter - Adapter to use

getAdapter

public PagerAdapter getAdapter()
Retrieve the current adapter supplying pages.

Returns:
The currently registered PagerAdapter

setCurrentItem

public void setCurrentItem(int item)
Set the currently selected page. If the ViewPager has already been through its first layout with its current adapter there will be a smooth animated transition between the current item and the specified item.

Parameters:
item - Item index to select

setCurrentItem

public void setCurrentItem(int item,
                           boolean smoothScroll)
Set the currently selected page.

Parameters:
item - Item index to select
smoothScroll - True to smoothly scroll to the new item, false to transition immediately

getCurrentItem

public int getCurrentItem()

setOnPageChangeListener

public void setOnPageChangeListener(ViewPager.OnPageChangeListener listener)
Set a listener that will be invoked whenever the page changes or is incrementally scrolled. See ViewPager.OnPageChangeListener.

Parameters:
listener - Listener to set

setPageTransformer

public 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. 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.

Parameters:
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 properties

getChildDrawingOrder

protected int getChildDrawingOrder(int childCount,
                                   int i)
Overrides:
getChildDrawingOrder in class android.view.ViewGroup

getOffscreenPageLimit

public int getOffscreenPageLimit()
Returns the number of pages that will be retained to either side of the current page in the view hierarchy in an idle state. Defaults to 1.

Returns:
How many pages will be kept offscreen on either side
See Also:
setOffscreenPageLimit(int)

setOffscreenPageLimit

public void setOffscreenPageLimit(int limit)
Set the number of pages that should be retained to either side of the current page in the view hierarchy in an idle state. Pages beyond this limit will be recreated from the adapter when needed.

This is offered as an optimization. If you know in advance the number of pages you will need to support or have lazy-loading mechanisms in place on your pages, tweaking this setting can have benefits in perceived smoothness of paging animations and interaction. If you have a small number of pages (3-4) that you can keep active all at once, less time will be spent in layout for newly created view subtrees as the user pages back and forth.

You should keep this limit low, especially if your pages have complex layouts. This setting defaults to 1.

Parameters:
limit - How many pages will be kept offscreen in an idle state.

setPageMargin

public void setPageMargin(int marginPixels)
Set the margin between pages.

Parameters:
marginPixels - Distance between adjacent pages in pixels
See Also:
getPageMargin(), setPageMarginDrawable(Drawable), setPageMarginDrawable(int)

getPageMargin

public int getPageMargin()
Return the margin between pages.

Returns:
The size of the margin in pixels

setPageMarginDrawable

public void setPageMarginDrawable(android.graphics.drawable.Drawable d)
Set a drawable that will be used to fill the margin between pages.

Parameters:
d - Drawable to display between pages

setPageMarginDrawable

public void setPageMarginDrawable(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

verifyDrawable

protected boolean verifyDrawable(android.graphics.drawable.Drawable who)
Overrides:
verifyDrawable in class android.view.View

drawableStateChanged

protected void drawableStateChanged()
Overrides:
drawableStateChanged in class android.view.ViewGroup

onSaveInstanceState

public android.os.Parcelable onSaveInstanceState()
Overrides:
onSaveInstanceState in class android.view.View

onRestoreInstanceState

public void onRestoreInstanceState(android.os.Parcelable state)
Overrides:
onRestoreInstanceState in class android.view.View

addView

public void addView(android.view.View child,
                    int index,
                    android.view.ViewGroup.LayoutParams params)
Overrides:
addView in class android.view.ViewGroup

removeView

public void removeView(android.view.View view)
Specified by:
removeView in interface android.view.ViewManager
Overrides:
removeView in class android.view.ViewGroup

onAttachedToWindow

protected void onAttachedToWindow()
Overrides:
onAttachedToWindow in class android.view.View

onMeasure

protected void onMeasure(int widthMeasureSpec,
                         int heightMeasureSpec)
Overrides:
onMeasure in class android.view.View

onSizeChanged

protected void onSizeChanged(int w,
                             int h,
                             int oldw,
                             int oldh)
Overrides:
onSizeChanged in class android.view.View

onLayout

protected void onLayout(boolean changed,
                        int l,
                        int t,
                        int r,
                        int b)
Specified by:
onLayout in class android.view.ViewGroup

computeScroll

public void computeScroll()
Overrides:
computeScroll in class android.view.View

onPageScrolled

protected void onPageScrolled(int position,
                              float offset,
                              int offsetPixels)
This method will be invoked when the current page is scrolled, either as part of a programmatically initiated smooth scroll or a user initiated touch scroll. If you override this method you must call through to the superclass implementation (e.g. super.onPageScrolled(position, offset, offsetPixels)) before onPageScrolled returns.

Parameters:
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.

onInterceptTouchEvent

public boolean onInterceptTouchEvent(android.view.MotionEvent ev)
Overrides:
onInterceptTouchEvent in class android.view.ViewGroup

onTouchEvent

public boolean onTouchEvent(android.view.MotionEvent ev)
Overrides:
onTouchEvent in class android.view.View

draw

public void draw(android.graphics.Canvas canvas)
Overrides:
draw in class android.view.View

onDraw

protected void onDraw(android.graphics.Canvas canvas)
Overrides:
onDraw in class android.view.View

beginFakeDrag

public boolean beginFakeDrag()
Start a fake drag of the pager.

A fake drag can be useful if you want to synchronize the motion of the ViewPager with the touch scrolling of another view, while still letting the ViewPager control the snapping motion and fling behavior. (e.g. parallax-scrolling tabs.) Call fakeDragBy(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.

Returns:
true if the fake drag began successfully, false if it could not be started.
See Also:
fakeDragBy(float), endFakeDrag()

endFakeDrag

public void endFakeDrag()
End a fake drag of the pager.

See Also:
beginFakeDrag(), fakeDragBy(float)

fakeDragBy

public 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.
See Also:
beginFakeDrag(), endFakeDrag()

isFakeDragging

public boolean isFakeDragging()
Returns true if a fake drag is in progress.

Returns:
true if currently in a fake drag, false otherwise.
See Also:
beginFakeDrag(), fakeDragBy(float), endFakeDrag()

canScroll

protected boolean canScroll(android.view.View v,
                            boolean checkV,
                            int dx,
                            int x,
                            int y)
Tests scrollability within child views of v given a delta of dx.

Parameters:
v - View to test for horizontal scrollability
checkV - Whether the view v passed should itself be checked for scrollability (true), or just its children (false).
dx - Delta scrolled in pixels
x - X coordinate of the active touch point
y - Y coordinate of the active touch point
Returns:
true if child views of v can be scrolled by delta of dx.

dispatchKeyEvent

public boolean dispatchKeyEvent(android.view.KeyEvent event)
Overrides:
dispatchKeyEvent in class android.view.ViewGroup

executeKeyEvent

public boolean executeKeyEvent(android.view.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.

Parameters:
event - The key event to execute.
Returns:
Return true if the event was handled, else false.

arrowScroll

public boolean arrowScroll(int direction)

addFocusables

public void addFocusables(ArrayList<android.view.View> views,
                          int direction,
                          int focusableMode)
We only want the current page that is being shown to be focusable.

Overrides:
addFocusables in class android.view.ViewGroup

addTouchables

public void addTouchables(ArrayList<android.view.View> views)
We only want the current page that is being shown to be touchable.

Overrides:
addTouchables in class android.view.ViewGroup

onRequestFocusInDescendants

protected boolean onRequestFocusInDescendants(int direction,
                                              android.graphics.Rect previouslyFocusedRect)
We only want the current page that is being shown to be focusable.

Overrides:
onRequestFocusInDescendants in class android.view.ViewGroup

dispatchPopulateAccessibilityEvent

public boolean dispatchPopulateAccessibilityEvent(android.view.accessibility.AccessibilityEvent event)
Overrides:
dispatchPopulateAccessibilityEvent in class android.view.View

generateDefaultLayoutParams

protected android.view.ViewGroup.LayoutParams generateDefaultLayoutParams()
Overrides:
generateDefaultLayoutParams in class android.view.ViewGroup

generateLayoutParams

protected android.view.ViewGroup.LayoutParams generateLayoutParams(android.view.ViewGroup.LayoutParams p)
Overrides:
generateLayoutParams in class android.view.ViewGroup

checkLayoutParams

protected boolean checkLayoutParams(android.view.ViewGroup.LayoutParams p)
Overrides:
checkLayoutParams in class android.view.ViewGroup

generateLayoutParams

public android.view.ViewGroup.LayoutParams generateLayoutParams(android.util.AttributeSet attrs)
Overrides:
generateLayoutParams in class android.view.ViewGroup


Copyright © 2013 Marek Kedzierski. All Rights Reserved.