GridViewPager

public class GridViewPager
extends ViewGroup

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


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.

Inherited constants

From class android.view.ViewGroup
From class android.view.View

Inherited fields

From class android.view.ViewGroup
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.

void measureChild(View child, GridViewPager.LayoutParams lp)

Used to measure all page views.

WindowInsets onApplyWindowInsets(WindowInsets insets)
void onAttachedToWindow()
boolean onInterceptTouchEvent(MotionEvent ev)
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 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 setConsumeWindowInsets(boolean consume)

Sets whether the grid view pager should consume insets during dispatchApplyWindowInsets(WindowInsets).

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.

void setSlideAnimationDuration(int slideAnimationDuration)

Protected methods

boolean checkLayoutParams(ViewGroup.LayoutParams p)
ViewGroup.LayoutParams generateDefaultLayoutParams()
ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p)
void onDetachedFromWindow()
void onLayout(boolean changed, int l, int t, int r, int b)
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
void onSizeChanged(int w, int h, int oldw, int oldh)

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

SCROLL_STATE_CONTENT_SETTLING

int SCROLL_STATE_CONTENT_SETTLING

Constant Value: 3 (0x00000003)

SCROLL_STATE_DRAGGING

int SCROLL_STATE_DRAGGING

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

Constant Value: 1 (0x00000001)

SCROLL_STATE_IDLE

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)

SCROLL_STATE_SETTLING

int SCROLL_STATE_SETTLING

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

Constant Value: 2 (0x00000002)

Public constructors

GridViewPager

GridViewPager (Context context)

Parameters
context Context

GridViewPager

GridViewPager (Context context,
                AttributeSet attrs)

Parameters
context Context
attrs AttributeSet

GridViewPager

GridViewPager (Context context,
                AttributeSet attrs,
                int defStyle)

Parameters
context Context
attrs AttributeSet
defStyle int

Public methods

addView

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

Parameters
child View
index int
params ViewGroup.LayoutParams

canScrollHorizontally

boolean canScrollHorizontally (int direction)

Parameters
direction int
Returns
boolean

canScrollVertically

boolean canScrollVertically (int direction)

Parameters
direction int
Returns
boolean

computeScroll

void computeScroll ()

dispatchApplyWindowInsets

WindowInsets dispatchApplyWindowInsets (WindowInsets insets)

Parameters
insets WindowInsets
Returns
WindowInsets

dispatchKeyEvent

boolean dispatchKeyEvent (KeyEvent event)

Parameters
event KeyEvent
Returns
boolean

generateLayoutParams

ViewGroup.LayoutParams generateLayoutParams (AttributeSet attrs)

Parameters
attrs AttributeSet
Returns
ViewGroup.LayoutParams

getAdapter

GridPagerAdapter getAdapter ()

Returns
GridPagerAdapter

getCurrentItem

Point getCurrentItem ()

Returns
Point

getOffscreenPageCount

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
int How many pages will be kept off-screen on all sides

See also:

getPageColumnMargin

int getPageColumnMargin ()

Return the margin between columns of pages.

Returns
int columnMarginPx horizontal distance between adjacent pages in pixels

getPageRowMargin

int getPageRowMargin ()

Returns the margin between rows of pages.

Returns
int the vertical distance between adjacent pages in pixels

measureChild

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.

Parameters
child View
lp GridViewPager.LayoutParams

onApplyWindowInsets

WindowInsets onApplyWindowInsets (WindowInsets insets)

Parameters
insets WindowInsets
Returns
WindowInsets

onAttachedToWindow

void onAttachedToWindow ()

onInterceptTouchEvent

boolean onInterceptTouchEvent (MotionEvent ev)

Parameters
ev MotionEvent
Returns
boolean

onPageScrolled

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

onRestoreInstanceState

void onRestoreInstanceState (Parcelable state)

Parameters
state Parcelable

onSaveInstanceState

Parcelable onSaveInstanceState ()

Returns
Parcelable

onTouchEvent

boolean onTouchEvent (MotionEvent ev)

Parameters
ev MotionEvent
Returns
boolean

removeView

void removeView (View view)

Parameters
view View

requestFitSystemWindows

void requestFitSystemWindows ()

scrollTo

void scrollTo (int x,
                int y)

Parameters
x int
y int

setAdapter

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 GridPagerAdapter: the adapter to assign

setConsumeWindowInsets

void setConsumeWindowInsets (boolean consume)

Sets whether the grid view pager should consume insets during dispatchApplyWindowInsets(WindowInsets). The default behavior is to consume insets.

Parameters
consume boolean: true to consume, false otherwise.

setOffscreenPageCount

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 int: How many pages will be kept offscreen in an idle state.

setOnAdapterChangeListener

void setOnAdapterChangeListener (GridViewPager.OnAdapterChangeListener listener)

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

Parameters
listener GridViewPager.OnAdapterChangeListener: Listener to set

setOnApplyWindowInsetsListener

void setOnApplyWindowInsetsListener (View.OnApplyWindowInsetsListener listener)

Parameters
listener View.OnApplyWindowInsetsListener

setOnPageChangeListener

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 GridViewPager.OnPageChangeListener: Listener to set

setPageMargins

void setPageMargins (int rowMarginPx,
                int columnMarginPx)

Sets the margin between pages.

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

setSlideAnimationDuration

void setSlideAnimationDuration (int slideAnimationDuration)

Parameters
slideAnimationDuration int

Protected methods

checkLayoutParams

boolean checkLayoutParams (ViewGroup.LayoutParams p)

Parameters
p ViewGroup.LayoutParams
Returns
boolean

generateDefaultLayoutParams

ViewGroup.LayoutParams generateDefaultLayoutParams ()

Returns
ViewGroup.LayoutParams

generateLayoutParams

ViewGroup.LayoutParams generateLayoutParams (ViewGroup.LayoutParams p)

Parameters
p ViewGroup.LayoutParams
Returns
ViewGroup.LayoutParams

onDetachedFromWindow

void onDetachedFromWindow ()

onLayout

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

Parameters
changed boolean
l int
t int
r int
b int

onMeasure

void onMeasure (int widthMeasureSpec,
                int heightMeasureSpec)

Parameters
widthMeasureSpec int
heightMeasureSpec int

onSizeChanged

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

Parameters
w int
h int
oldw int
oldh int