GridViewPager

public class GridViewPager
extends ViewGroup

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


布局管理器,允许用户通过内容页面纵向和横向导航。 您提供了一个GridPagerAdapter的实现来生成要显示的视图的页面。

Summary

Nested classes

class GridViewPager.LayoutParams

应该为添加到ViewPager的视图提供的布局参数。

interface GridViewPager.OnAdapterChangeListener

回叫接口,用于响应已替换或已移除的适配器。

interface GridViewPager.OnPageChangeListener

回调界面,用于响应所选页面的更改状态。

Constants

int SCROLL_STATE_CONTENT_SETTLING

int SCROLL_STATE_DRAGGING

表示该传呼机当前正在被用户拖动。

int SCROLL_STATE_IDLE

表示寻呼机处于闲置状态。

int SCROLL_STATE_SETTLING

表示寻呼机正处于结算位置。

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()

返回处于空闲状态的视图层次结构中当前页面两侧将保留的页数。

int getPageColumnMargin()

返回页面之间的页边空白。

int getPageRowMargin()

返回页面行之间的边距。

void measureChild(View child, GridViewPager.LayoutParams lp)

用于测量所有页面视图。

WindowInsets onApplyWindowInsets(WindowInsets insets)
void onAttachedToWindow()
boolean onInterceptTouchEvent(MotionEvent ev)
void onPageScrolled(int positionX, int positionY, float offsetX, float offsetY, int offsetLeftPx, int offsetTopPx)

此方法将在当前页面滚动时调用,或者作为程序启动的平滑滚动的一部分或用户启动的触摸滚动。

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)

分配一个适配器为该寻呼机提供内容。

void setConsumeWindowInsets(boolean consume)

设置网格视图传呼机是否应在 dispatchApplyWindowInsets(WindowInsets)期间消耗 dispatchApplyWindowInsets(WindowInsets)

void setOffscreenPageCount(int limit)

将闲置状态下应保留在视图层次结构中当前页面任一侧的页数。

void setOnAdapterChangeListener(GridViewPager.OnAdapterChangeListener listener)

设置一个侦听器,只要适配器发生变化就会调用它。

void setOnApplyWindowInsetsListener(View.OnApplyWindowInsetsListener listener)
void setOnPageChangeListener(GridViewPager.OnPageChangeListener listener)

设置一个侦听器,每当页面发生变化或增量滚动时都会调用该侦听器。

void setPageMargins(int rowMarginPx, int columnMarginPx)

设置页面之间的页边距。

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

常量值:3(0x00000003)

SCROLL_STATE_DRAGGING

int SCROLL_STATE_DRAGGING

表示该传呼机当前正在被用户拖动。

常数值:1(0x00000001)

SCROLL_STATE_IDLE

int SCROLL_STATE_IDLE

表示寻呼机处于闲置状态。 当前页面处于完全状态,并且没有动画正在进行。

常量值:0(0x00000000)

SCROLL_STATE_SETTLING

int SCROLL_STATE_SETTLING

表示寻呼机正处于结算位置。

常量值: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 ()

返回处于空闲状态的视图层次结构中当前页面两侧将保留的页数。 默认为1。

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

也可以看看:

getPageColumnMargin

int getPageColumnMargin ()

返回页面之间的页边空白。

Returns
int columnMarginPx horizontal distance between adjacent pages in pixels

getPageRowMargin

int getPageRowMargin ()

返回页面行之间的边距。

Returns
int the vertical distance between adjacent pages in pixels

measureChild

void measureChild (View child,
                GridViewPager.LayoutParams lp)

用于测量所有页面视图。 尺寸为match_parent或特定尺寸的视图将被完全测量,而那些包含wrap_content的视图将被视为“未注册”以允许它们变得尽可能大。

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)

此方法将在当前页面滚动时调用,或者作为程序启动的平滑滚动的一部分或用户启动的触摸滚动。 如果您重写此方法,则必须在onPageScrolled返回前调用超类实现(例如,super.onPageScrolled(position,offset,offsetPixels))。

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)

分配一个适配器为该寻呼机提供内容。 任何现有的内容都被删除并丢弃,并且位置被重置为0,0。

Parameters
adapter GridPagerAdapter: the adapter to assign

setConsumeWindowInsets

void setConsumeWindowInsets (boolean consume)

设置dispatchApplyWindowInsets(WindowInsets)期间网格视图传呼机是否应该消耗dispatchApplyWindowInsets(WindowInsets) 默认行为是消费插页。

Parameters
consume boolean: true to consume, false otherwise.

setOffscreenPageCount

void setOffscreenPageCount (int limit)

将闲置状态下应保留在视图层次结构中当前页面任一侧的页数。 超出此限制的页面将在需要时从适配器重新创建。

这是作为优化提供的。 如果您事先知道您需要支持的页面数量或者在您的页面上放置了延迟加载机制,那么调整此设置可以在分页动画和交互的感知平滑度方面带来好处。 如果您有一小部分页面(3-4)可以一次保持活动状态,那么随着用户来回翻页,新创建的视图子树的布局花费的时间会更少。

你应该保持低限,特别是如果你的页面有复杂的布局。 该设置默认为1。

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

setOnAdapterChangeListener

void setOnAdapterChangeListener (GridViewPager.OnAdapterChangeListener listener)

设置一个侦听器,只要适配器发生变化就会调用它。 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)

设置一个侦听器,每当页面发生变化或增量滚动时都会调用该侦听器。 GridViewPager.OnPageChangeListener

Parameters
listener GridViewPager.OnPageChangeListener: Listener to set

setPageMargins

void setPageMargins (int rowMarginPx,
                int columnMarginPx)

设置页面之间的页边距。

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