public class

GridViewPager

extends ViewGroup

Note: The Wearable Support Library classes under the android.support.wearable package are subject to change. For the full Android API reference, see Reference.

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.support.wearable.view.GridViewPager

Class Overview

Layout manager that allows the user to navigate both vertically and horizontally through pages of content. You supply an implementation of a GridPagerAdapter to generate pages for the view to show.

Summary

Nested Classes
class GridViewPager.LayoutParams Layout parameters that should be supplied for views added to a ViewPager. 
interface GridViewPager.OnAdapterChangeListener Callback interface for responding to a replaced or removed adapter. 
interface GridViewPager.OnPageChangeListener Callback interface for responding to changing state of the selected page. 
Constants
int SCROLL_STATE_CONTENT_SETTLING
int SCROLL_STATE_DRAGGING Indicates that the pager is currently being dragged by the user.
int SCROLL_STATE_IDLE Indicates that the pager is in an idle, settled state.
int SCROLL_STATE_SETTLING Indicates that the pager is in the process of settling to a final position.
[Expand]
Inherited Constants
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
GridViewPager(Context context)
GridViewPager(Context context, AttributeSet attrs)
GridViewPager(Context context, AttributeSet attrs, int defStyle)
Public Methods
void addView(View child, int index, ViewGroup.LayoutParams params)
boolean canScrollHorizontally(int direction)
boolean canScrollVertically(int direction)
void computeScroll()
WindowInsets dispatchApplyWindowInsets(WindowInsets insets)
boolean dispatchKeyEvent(KeyEvent event)
ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs)
GridPagerAdapter getAdapter()
Point getCurrentItem()
int getOffscreenPageCount()
Returns the number of pages that will be retained on the sides of the current page in the view hierarchy in an idle state.
int getPageColumnMargin()
Return the margin between columns of pages.
int getPageRowMargin()
Returns the margin between rows of pages.
WindowInsets onApplyWindowInsets(WindowInsets insets)
void onAttachedToWindow()
boolean onInterceptTouchEvent(MotionEvent ev)
void onRestoreInstanceState(Parcelable state)
Parcelable onSaveInstanceState()
boolean onTouchEvent(MotionEvent ev)
void removeView(View view)
void requestFitSystemWindows()
void scrollTo(int x, int y)
void setAdapter(GridPagerAdapter adapter)
Assigns an adapter to provide the content for this pager.
void setOffscreenPageCount(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 setOnAdapterChangeListener(GridViewPager.OnAdapterChangeListener listener)
Set a listener that will be invoked whenever the adapter is changed.
void setOnApplyWindowInsetsListener(View.OnApplyWindowInsetsListener listener)
void setOnPageChangeListener(GridViewPager.OnPageChangeListener listener)
Set a listener that will be invoked whenever the page changes or is incrementally scrolled.
void setPageMargins(int rowMarginPx, int columnMarginPx)
Sets the margin between pages.
Protected Methods
boolean checkLayoutParams(ViewGroup.LayoutParams p)
static String debugIndent(int depth)
ViewGroup.LayoutParams generateDefaultLayoutParams()
ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p)
void measureChild(View child, GridViewPager.LayoutParams lp)
Used to measure all page views.
void onDetachedFromWindow()
void onLayout(boolean changed, int l, int t, int r, int b)
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
void onPageScrolled(int positionX, int positionY, float offsetX, float offsetY, int offsetLeftPx, int offsetTopPx)
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.
void onSizeChanged(int w, int h, int oldw, int oldh)
[Expand]
Inherited Methods
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.view.ViewParent
From interface android.view.ViewManager
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource

Constants

public static final int SCROLL_STATE_CONTENT_SETTLING

Constant Value: 3 (0x00000003)

public static final int SCROLL_STATE_DRAGGING

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

Constant Value: 1 (0x00000001)

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.

Constant Value: 0 (0x00000000)

public static final int SCROLL_STATE_SETTLING

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

Constant Value: 2 (0x00000002)

Public Constructors

public GridViewPager (Context context)

public GridViewPager (Context context, AttributeSet attrs)

public GridViewPager (Context context, AttributeSet attrs, int defStyle)

Public Methods

public void addView (View child, int index, ViewGroup.LayoutParams params)

public boolean canScrollHorizontally (int direction)

public boolean canScrollVertically (int direction)

public void computeScroll ()

public WindowInsets dispatchApplyWindowInsets (WindowInsets insets)

public boolean dispatchKeyEvent (KeyEvent event)

public ViewGroup.LayoutParams generateLayoutParams (AttributeSet attrs)

public GridPagerAdapter getAdapter ()

public Point getCurrentItem ()

public int getOffscreenPageCount ()

Returns the number of pages that will be retained on the sides of the current page in the view hierarchy in an idle state. Defaults to 1.

Returns
  • How many pages will be kept off-screen on all sides

public int getPageColumnMargin ()

Return the margin between columns of pages.

Returns
  • columnMarginPx horizontal distance between adjacent pages in pixels

public int getPageRowMargin ()

Returns the margin between rows of pages.

Returns
  • the vertical distance between adjacent pages in pixels

public WindowInsets onApplyWindowInsets (WindowInsets insets)

public void onAttachedToWindow ()

public boolean onInterceptTouchEvent (MotionEvent ev)

public void onRestoreInstanceState (Parcelable state)

public Parcelable onSaveInstanceState ()

public boolean onTouchEvent (MotionEvent ev)

public void removeView (View view)

public void requestFitSystemWindows ()

public void scrollTo (int x, int y)

public void setAdapter (GridPagerAdapter adapter)

Assigns an adapter to provide the content for this pager. Any existing content is removed and discarded and the position is reset to 0,0.

Parameters
adapter the adapter to assign

public void setOffscreenPageCount (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.

public void setOnAdapterChangeListener (GridViewPager.OnAdapterChangeListener listener)

Set a listener that will be invoked whenever the adapter is changed. See GridViewPager.OnAdapterChangeListener.

Parameters
listener Listener to set

public void setOnApplyWindowInsetsListener (View.OnApplyWindowInsetsListener listener)

public void setOnPageChangeListener (GridViewPager.OnPageChangeListener listener)

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

Parameters
listener Listener to set

public void setPageMargins (int rowMarginPx, int columnMarginPx)

Sets the margin between pages.

Parameters
rowMarginPx vertical distance between adjacent pages in pixels
columnMarginPx horizontal distance between adjacent pages in pixels

Protected Methods

protected boolean checkLayoutParams (ViewGroup.LayoutParams p)

protected static String debugIndent (int depth)

protected ViewGroup.LayoutParams generateDefaultLayoutParams ()

protected ViewGroup.LayoutParams generateLayoutParams (ViewGroup.LayoutParams p)

protected void measureChild (View child, GridViewPager.LayoutParams lp)

Used to measure all page views. Views with a dimension of match_parent or a specific size will be measured with EXACTLY, while those with wrap_content will be measured as UNSPECIFIED to allow them to become as large as desired.

protected void onDetachedFromWindow ()

protected void onLayout (boolean changed, int l, int t, int r, int b)

protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)

protected void onPageScrolled (int positionX, int positionY, float offsetX, float offsetY, int offsetLeftPx, int offsetTopPx)

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
positionX column index of the first page currently being displayed. Page positionX+1 will be visible if offsetX is nonzero.
positionY row index of the first page currently being displayed. Page positionY+1 will be visible if offseyY is nonzero.
offsetX Value from [0, 1) indicating the left offset from the page at positionX.
offsetY Value from [0, 1) indicating the top offset from the page at positionY.
offsetLeftPx Value in pixels indicating the offset from positionX.
offsetTopPx Value in pixels indicating the offset from positionY.

protected void onSizeChanged (int w, int h, int oldw, int oldh)