Register now for Android Dev Summit 2019!

BaseGridView

abstract class BaseGridView : RecyclerView
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ androidx.recyclerview.widget.RecyclerView
   ↳ androidx.leanback.widget.BaseGridView

An abstract base class for vertically and horizontally scrolling lists. The items come from the RecyclerView.Adapter associated with this view. Do not directly use this class, use VerticalGridView and HorizontalGridView. The class is not intended to be subclassed other than VerticalGridView and HorizontalGridView.

Summary

Nested classes

abstract

Listener for intercepting key dispatch events.

abstract

Listener for intercepting generic motion dispatch events.

abstract

Listener for intercepting touch dispatch events.

abstract

Constants

static Float

Value indicates that percent is not used.

static Int

Save on screen views plus save off screen child views without any limitation.

static Int

Save on screen views plus save off screen child views states up to getSaveChildrenLimitNumber().

static Int

Dont save states of any child views.

static Int

Only save on screen child views, the states are lost when they become off screen.

static Int

The first item and last item are aligned with the two edges of the viewport.

static Int

The last item is aligned with the high edge of the viewport when navigating to the end of list.

static Int

The first item is aligned with the low edge of the viewport.

static Int

The focused item always stays in a key line location.

static Float

Value indicates that percent is not used.

Inherited constants

Public methods

open Unit

Registers a callback to be invoked when an item in BaseGridView has been selected.

open Unit

Undo animateOut() and slide in child views.

open Unit

Temporarily slide out child views to bottom (for VerticalGridView) or end (for HorizontalGridView).

open Boolean

open Boolean

open View!
focusSearch(direction: Int)

open Int
getChildDrawingOrder(childCount: Int, i: Int)

open Int

Returns the spacing in pixels between two child items horizontally.

open Int

Returns the horizontal spacing in pixels between two child items.

open Int

Gets the number of items to prefetch in RecyclerView.LayoutManager#collectInitialPrefetchPositions(int, RecyclerView.LayoutManager.LayoutPrefetchRegistry), which defines how many inner items should be prefetched when this GridView is nested inside another RecyclerView.

open Int

Returns number of pixels to the end of low edge.

open Float

Returns the offset percent for item alignment in addition to .

open Int

Returns the id of the view to align with, or android.view.View#NO_ID for the root RecyclerView.ViewHolder#itemView.

open BaseGridView.OnUnhandledKeyListener!

Returns the unhandled key listener.

Int

Returns the limit used when when getSaveChildrenPolicy() is SAVE_LIMITED_CHILD

Int

Returns the policy for saving children.

open Int

Returns the adapter position of selected item.

open Int

Returns the spacing in pixels between two child items vertically.

open Int

Returns the vertical spacing in pixels between two child items.

open Unit
getViewSelectedOffsets(view: View!, offsets: IntArray!)

Returns the x/y offsets to final position from current position if the view is selected.

open Int

Returns the method for focused item alignment in the view.

open Int

Returns the offset in pixels for window alignment key line.

open Float

Returns the offset percent for window alignment key line in addition to getWindowAlignmentOffset().

open Boolean

open Boolean

Returns true if the view at the given position has a same row sibling in front of it.

open Boolean

Returns true if an animation will run when a child changes size or when adding or removing a child.

open Boolean

Returns true if draws selected child at last, false otherwise.

Boolean

Returns true if focus search is disabled.

open Boolean

Returns true if applies padding to item alignment when getItemAlignmentOffsetPercent() is 0 or 100; returns false otherwise.

open Boolean

Returns true if scrolling is enabled, false otherwise.

open Boolean

Returns whether prefer key line over high edge when WINDOW_ALIGN_HIGH_EDGE is used.

open Boolean

Returns whether prefer key line over low edge when WINDOW_ALIGN_LOW_EDGE is used.

open Boolean
onRequestFocusInDescendants(direction: Int, previouslyFocusedRect: Rect!)

open Unit
onRtlPropertiesChanged(layoutDirection: Int)

Notify layout manager that layout directionality has been updated

open Unit

Remove the callback invoked when an item in BaseGridView has been selected.

open Unit
removeView(view: View!)

open Unit
removeViewAt(index: Int)

open Unit
scrollToPosition(position: Int)

open Unit
setAnimateChildLayout(animateChildLayout: Boolean)

Sets whether ItemAnimator should run when a child changes size or when adding or removing a child.

open Unit

Changes and overrides children's visibility.

open Unit

Enables or disables the default "focus draw at last" order rule.

Unit

Disables or enables focus search.

open Unit
setGravity(gravity: Int)

Sets the gravity used for child view positioning.

open Unit

open Unit

Sets the spacing in pixels between two child items horizontally.

open Unit

Sets the horizontal spacing in pixels between two child items.

open Unit

Sets the number of items to prefetch in RecyclerView.LayoutManager#collectInitialPrefetchPositions(int, RecyclerView.LayoutManager.LayoutPrefetchRegistry), which defines how many inner items should be prefetched when this GridView is nested inside another RecyclerView.

open Unit

Sets number of pixels to the end of low edge.

open Unit

Sets the offset percent for item alignment in addition to .

open Unit

Sets whether applies padding to item alignment when getItemAlignmentOffsetPercent() is 0 or 100.

open Unit

Sets the id of the view to align with.

open Unit
setItemMargin(margin: Int)

Sets the spacing in pixels between two child items.

open Unit
setItemSpacing(spacing: Int)

Sets the vertical and horizontal spacing in pixels between two child items.

open Unit
setLayoutEnabled(layoutEnabled: Boolean)

Enables or disables layout.

open Unit

Registers a callback to be invoked when an item in BaseGridView has been laid out.

open Unit

Registers a callback to be invoked when an item in BaseGridView has been selected.

open Unit

Registers a callback to be invoked when an item in BaseGridView has been selected.

open Unit

Sets the key intercept listener.

open Unit

Sets the generic motion intercept listener.

open Unit

Sets the touch intercept listener.

open Unit

Sets the unhandled key listener.

open Unit
setPruneChild(pruneChild: Boolean)

Enables or disables pruning of children.

open Unit

Unit

Sets the limit number when getSaveChildrenPolicy() is SAVE_LIMITED_CHILD.

Unit

Sets the policy for saving children.

open Unit
setScrollEnabled(scrollEnabled: Boolean)

Enables or disables scrolling.

open Unit

Changes the selected item immediately without animation.

open Unit
setSelectedPosition(position: Int, scrollExtra: Int)

Changes the selected item immediately without animation, scrollExtra is applied in primary scroll direction.

open Unit

Perform a task on ViewHolder at given position after scroll to it.

open Unit

Changes the selected item and run an animation to scroll to the target position.

open Unit

Perform a task on ViewHolder at given position after smooth scrolling to it.

open Unit

Sets the spacing in pixels between two child items vertically.

open Unit

Sets the vertical spacing in pixels between two child items.

open Unit
setWindowAlignment(windowAlignment: Int)

Sets the method for focused item alignment in the view.

open Unit

Sets the offset in pixels for window alignment key line.

open Unit

Sets the offset percent for window alignment key line in addition to .

open Unit

Returns whether prefer key line over high edge when WINDOW_ALIGN_HIGH_EDGE is used.

open Unit

Sets whether prefer key line over low edge when WINDOW_ALIGN_LOW_EDGE is used.

open Unit

Protected methods

open Boolean

open Unit
onFocusChanged(gainFocus: Boolean, direction: Int, previouslyFocusedRect: Rect!)

Inherited functions

Constants

ITEM_ALIGN_OFFSET_PERCENT_DISABLED

static val ITEM_ALIGN_OFFSET_PERCENT_DISABLED: Float

Value indicates that percent is not used.

Value: ItemAlignmentFacet.ITEM_ALIGN_OFFSET_PERCENT_DISABLED

SAVE_ALL_CHILD

static val SAVE_ALL_CHILD: Int

Save on screen views plus save off screen child views without any limitation. This might cause out of memory, only use it when you are dealing with limited data.

Value: 3

SAVE_LIMITED_CHILD

static val SAVE_LIMITED_CHILD: Int

Save on screen views plus save off screen child views states up to getSaveChildrenLimitNumber().

Value: 2

SAVE_NO_CHILD

static val SAVE_NO_CHILD: Int

Dont save states of any child views.

Value: 0

SAVE_ON_SCREEN_CHILD

static val SAVE_ON_SCREEN_CHILD: Int

Only save on screen child views, the states are lost when they become off screen.

Value: 1

WINDOW_ALIGN_BOTH_EDGE

static val WINDOW_ALIGN_BOTH_EDGE: Int

The first item and last item are aligned with the two edges of the viewport. When navigating in the middle of list, the focus maintains a key line location.

The key line location is calculated by "windowAlignOffset" and "windowAlignOffsetPercent"; if neither of these two is defined, the default value is 1/2 of the size.

Value: WINDOW_ALIGN_LOW_EDGE | WINDOW_ALIGN_HIGH_EDGE

WINDOW_ALIGN_HIGH_EDGE

static val WINDOW_ALIGN_HIGH_EDGE: Int

The last item is aligned with the high edge of the viewport when navigating to the end of list. When navigating away from the end, the focus item is aligned to a key line location.

For HorizontalGridView, high edge refers to getWidth() - getPaddingRight() when RTL is false or getPaddingLeft() when RTL is true. For VerticalGridView, high edge refers to getHeight() - getPaddingBottom().

The key line location is calculated by "windowAlignOffset" and "windowAlignOffsetPercent"; if neither of these two is defined, the default value is 1/2 of the size.

Note if there are very few items between high edge and key line, use setWindowAlignmentPreferKeyLineOverHighEdge(boolean) to control whether you prefer to align the items to key line or high edge. Default is preferring key line.

Value: 1 << 1

WINDOW_ALIGN_LOW_EDGE

static val WINDOW_ALIGN_LOW_EDGE: Int

The first item is aligned with the low edge of the viewport. When navigating away from the first item, the focus item is aligned to a key line location.

For HorizontalGridView, low edge refers to getPaddingLeft() when RTL is false or getWidth() - getPaddingRight() when RTL is true. For VerticalGridView, low edge refers to getPaddingTop().

The key line location is calculated by "windowAlignOffset" and "windowAlignOffsetPercent"; if neither of these two is defined, the default value is 1/2 of the size.

Note if there are very few items between low edge and key line, use setWindowAlignmentPreferKeyLineOverLowEdge(boolean) to control whether you prefer to align the items to key line or low edge. Default is preferring low edge.

Value: 1

WINDOW_ALIGN_NO_EDGE

static val WINDOW_ALIGN_NO_EDGE: Int

The focused item always stays in a key line location.

The key line location is calculated by "windowAlignOffset" and "windowAlignOffsetPercent"; if neither of these two is defined, the default value is 1/2 of the size.

Value: 0

WINDOW_ALIGN_OFFSET_PERCENT_DISABLED

static val WINDOW_ALIGN_OFFSET_PERCENT_DISABLED: Float

Value indicates that percent is not used.

Value: -1

Public methods

addOnChildViewHolderSelectedListener

open fun addOnChildViewHolderSelectedListener(listener: OnChildViewHolderSelectedListener!): Unit

Registers a callback to be invoked when an item in BaseGridView has been selected. Note that the listener may be invoked when there is a layout pending on the view, affording the listener an opportunity to adjust the upcoming layout based on the selection state.

Parameters
listener OnChildViewHolderSelectedListener!: The listener to be invoked.

animateIn

open fun animateIn(): Unit

Undo animateOut() and slide in child views.

animateOut

open fun animateOut(): Unit

Temporarily slide out child views to bottom (for VerticalGridView) or end (for HorizontalGridView). Layout and scrolling will be suppressed until animateIn() is called.

dispatchKeyEvent

open fun dispatchKeyEvent(event: KeyEvent!): Boolean

dispatchTouchEvent

open fun dispatchTouchEvent(event: MotionEvent!): Boolean

focusSearch

open fun focusSearch(direction: Int): View!

getChildDrawingOrder

open fun getChildDrawingOrder(childCount: Int, i: Int): Int

getHorizontalMargin

open fun getHorizontalMargin(): Int

Deprecated: Use getHorizontalSpacing()

Returns the spacing in pixels between two child items horizontally.

getHorizontalSpacing

open fun getHorizontalSpacing(): Int

Returns the horizontal spacing in pixels between two child items.

Return
Int: The Horizontal spacing in pixels between two child items.

getInitialPrefetchItemCount

open fun getInitialPrefetchItemCount(): Int

Gets the number of items to prefetch in RecyclerView.LayoutManager#collectInitialPrefetchPositions(int, RecyclerView.LayoutManager.LayoutPrefetchRegistry), which defines how many inner items should be prefetched when this GridView is nested inside another RecyclerView.

Return
Int: number of items to prefetch.

getItemAlignmentOffset

open fun getItemAlignmentOffset(): Int

Returns number of pixels to the end of low edge. Supports right to left layout direction. In left to right or vertical case, it's the offset added to left/top edge. In right to left case, it's the offset subtracted from right edge. Item alignment settings are ignored for the child if ItemAlignmentFacet is provided by RecyclerView.ViewHolder or FacetProviderAdapter.

Return
Int: The number of pixels to the end of low edge.

getItemAlignmentOffsetPercent

open fun getItemAlignmentOffsetPercent(): Float

Returns the offset percent for item alignment in addition to .

Return
Float: Percentage to offset. E.g., 40 means 40% of the width from the low edge, or ITEM_ALIGN_OFFSET_PERCENT_DISABLED if disabled. Default value is 50.

getItemAlignmentViewId

open fun getItemAlignmentViewId(): Int

Returns the id of the view to align with, or android.view.View#NO_ID for the root RecyclerView.ViewHolder#itemView.

Return
Int: The id of the view to align with, or android.view.View#NO_ID for the root RecyclerView.ViewHolder#itemView.

getOnUnhandledKeyListener

open fun getOnUnhandledKeyListener(): BaseGridView.OnUnhandledKeyListener!

Returns the unhandled key listener.

Return
BaseGridView.OnUnhandledKeyListener!: The unhandled key listener.

getSaveChildrenLimitNumber

fun getSaveChildrenLimitNumber(): Int

Returns the limit used when when getSaveChildrenPolicy() is SAVE_LIMITED_CHILD

getSaveChildrenPolicy

fun getSaveChildrenPolicy(): Int

Returns the policy for saving children.

Return
Int: policy, one of SAVE_NO_CHILD SAVE_ON_SCREEN_CHILD SAVE_LIMITED_CHILD SAVE_ALL_CHILD.

getSelectedPosition

open fun getSelectedPosition(): Int

Returns the adapter position of selected item.

Return
Int: The adapter position of selected item.

getVerticalMargin

open fun getVerticalMargin(): Int

Deprecated: Use getVerticalSpacing()

Returns the spacing in pixels between two child items vertically.

getVerticalSpacing

open fun getVerticalSpacing(): Int

Returns the vertical spacing in pixels between two child items.

Return
Int: The vertical spacing in pixels between two child items.

getViewSelectedOffsets

open fun getViewSelectedOffsets(view: View!, offsets: IntArray!): Unit

Returns the x/y offsets to final position from current position if the view is selected.

Parameters
view View!: The view to get offsets.
offsets View!: offsets[0] holds offset of X, offsets[1] holds offset of Y.

getWindowAlignment

open fun getWindowAlignment(): Int

Returns the method for focused item alignment in the view.

Return
Int: WINDOW_ALIGN_BOTH_EDGE, WINDOW_ALIGN_LOW_EDGE, WINDOW_ALIGN_HIGH_EDGE or WINDOW_ALIGN_NO_EDGE.

getWindowAlignmentOffset

open fun getWindowAlignmentOffset(): Int

Returns the offset in pixels for window alignment key line.

Return
Int: The number of pixels to offset. If the offset is positive, it is distance from low edge (see WINDOW_ALIGN_LOW_EDGE); if the offset is negative, the absolute value is distance from high edge (see WINDOW_ALIGN_HIGH_EDGE). Default value is 0.

getWindowAlignmentOffsetPercent

open fun getWindowAlignmentOffsetPercent(): Float

Returns the offset percent for window alignment key line in addition to getWindowAlignmentOffset().

Return
Float: Percentage to offset. E.g., 40 means 40% of the width from the low edge, or WINDOW_ALIGN_OFFSET_PERCENT_DISABLED if disabled. Default value is 50.

hasOverlappingRendering

open fun hasOverlappingRendering(): Boolean

hasPreviousViewInSameRow

open fun hasPreviousViewInSameRow(position: Int): Boolean

Returns true if the view at the given position has a same row sibling in front of it. This will return true if first item view is not created.

Parameters
position Int: Position in adapter.
Return
Boolean: True if the view at the given position has a same row sibling in front of it.

isChildLayoutAnimated

open fun isChildLayoutAnimated(): Boolean

Returns true if an animation will run when a child changes size or when adding or removing a child.

Return
Boolean: True if ItemAnimator is enabled, false otherwise.

isFocusDrawingOrderEnabled

open fun isFocusDrawingOrderEnabled(): Boolean

Returns true if draws selected child at last, false otherwise. Default is enabled.

Return
Boolean: True if draws selected child at last, false otherwise.

isFocusSearchDisabled

fun isFocusSearchDisabled(): Boolean

Returns true if focus search is disabled.

Return
Boolean: True if focus search is disabled.

isItemAlignmentOffsetWithPadding

open fun isItemAlignmentOffsetWithPadding(): Boolean

Returns true if applies padding to item alignment when getItemAlignmentOffsetPercent() is 0 or 100; returns false otherwise.

When true: Applies start/top padding when getItemAlignmentOffsetPercent() is 0. Applies end/bottom padding when getItemAlignmentOffsetPercent() is 100. Does not apply padding if getItemAlignmentOffsetPercent() is neither 0 nor 100.

When false: does not apply padding

isScrollEnabled

open fun isScrollEnabled(): Boolean

Returns true if scrolling is enabled, false otherwise.

Return
Boolean: True if scrolling is enabled, false otherwise.

isWindowAlignmentPreferKeyLineOverHighEdge

open fun isWindowAlignmentPreferKeyLineOverHighEdge(): Boolean

Returns whether prefer key line over high edge when WINDOW_ALIGN_HIGH_EDGE is used. When true, if there are very few items between high edge and key line, align items to key line instead of align items to high edge. Default value is true (aka prefer align to key line).

Return
Boolean: True to prefer key line over high edge, false otherwise.

isWindowAlignmentPreferKeyLineOverLowEdge

open fun isWindowAlignmentPreferKeyLineOverLowEdge(): Boolean

Returns whether prefer key line over low edge when WINDOW_ALIGN_LOW_EDGE is used. When true, if there are very few items between low edge and key line, align items to key line instead of align items to low edge. Default value is false (aka prefer align to low edge).

Return
Boolean: True to prefer key line over low edge, false otherwise.

onRequestFocusInDescendants

open fun onRequestFocusInDescendants(direction: Int, previouslyFocusedRect: Rect!): Boolean

onRtlPropertiesChanged

open fun onRtlPropertiesChanged(layoutDirection: Int): Unit

Notify layout manager that layout directionality has been updated

removeOnChildViewHolderSelectedListener

open fun removeOnChildViewHolderSelectedListener(listener: OnChildViewHolderSelectedListener!): Unit

Remove the callback invoked when an item in BaseGridView has been selected.

Parameters
listener OnChildViewHolderSelectedListener!: The listener to be removed.

removeView

open fun removeView(view: View!): Unit

removeViewAt

open fun removeViewAt(index: Int): Unit

scrollToPosition

open fun scrollToPosition(position: Int): Unit

setAnimateChildLayout

open fun setAnimateChildLayout(animateChildLayout: Boolean): Unit

Sets whether ItemAnimator should run when a child changes size or when adding or removing a child.

Parameters
animateChildLayout Boolean: True to enable ItemAnimator, false to disable.

setChildrenVisibility

open fun setChildrenVisibility(visibility: Int): Unit

Changes and overrides children's visibility.

Parameters
visibility Int: See View#getVisibility().

setFocusDrawingOrderEnabled

open fun setFocusDrawingOrderEnabled(enabled: Boolean): Unit

Enables or disables the default "focus draw at last" order rule. Default is enabled.

Parameters
enabled Boolean: True to draw the selected child at last, false otherwise.

setFocusSearchDisabled

fun setFocusSearchDisabled(disabled: Boolean): Unit

Disables or enables focus search.

Parameters
disabled Boolean: True to disable focus search, false to enable.

setGravity

open fun setGravity(gravity: Int): Unit

Sets the gravity used for child view positioning. Defaults to GRAVITY_TOP|GRAVITY_START.

Parameters
gravity Int: See android.view.Gravity

setHasOverlappingRendering

open fun setHasOverlappingRendering(hasOverlapping: Boolean): Unit

setHorizontalMargin

open fun setHorizontalMargin(margin: Int): Unit

Deprecated: Use setHorizontalSpacing(int)

Sets the spacing in pixels between two child items horizontally.

setHorizontalSpacing

open fun setHorizontalSpacing(spacing: Int): Unit

Sets the horizontal spacing in pixels between two child items.

Parameters
spacing Int: Horizontal spacing in pixels between two child items.

setInitialPrefetchItemCount

open fun setInitialPrefetchItemCount(itemCount: Int): Unit

Sets the number of items to prefetch in RecyclerView.LayoutManager#collectInitialPrefetchPositions(int, RecyclerView.LayoutManager.LayoutPrefetchRegistry), which defines how many inner items should be prefetched when this GridView is nested inside another RecyclerView.

Set this value to the number of items this inner GridView will display when it is first scrolled into the viewport. RecyclerView will attempt to prefetch that number of items so they are ready, avoiding jank as the inner GridView is scrolled into the viewport.

For example, take a VerticalGridView of scrolling HorizontalGridViews. The rows always have 6 items visible in them (or 7 if not aligned). Passing 6 to this method for each inner GridView will enable RecyclerView's prefetching feature to do create/bind work for 6 views within a row early, before it is scrolled on screen, instead of just the default 4.

Calling this method does nothing unless the LayoutManager is in a RecyclerView nested in another RecyclerView.

Note: Setting this value to be larger than the number of views that will be visible in this view can incur unnecessary bind work, and an increase to the number of Views created and in active use.

Parameters
itemCount Int: Number of items to prefetch

setItemAlignmentOffset

open fun setItemAlignmentOffset(offset: Int): Unit

Sets number of pixels to the end of low edge. Supports right to left layout direction. Item alignment settings are ignored for the child if ItemAlignmentFacet is provided by RecyclerView.ViewHolder or FacetProviderAdapter.

Parameters
offset Int: In left to right or vertical case, it's the offset added to left/top edge. In right to left case, it's the offset subtracted from right edge.

setItemAlignmentOffsetPercent

open fun setItemAlignmentOffsetPercent(offsetPercent: Float): Unit

Sets the offset percent for item alignment in addition to . Item alignment settings are ignored for the child if ItemAlignmentFacet is provided by RecyclerView.ViewHolder or FacetProviderAdapter.

Parameters
offsetPercent Float: Percentage to offset. E.g., 40 means 40% of the width from the low edge. Use ITEM_ALIGN_OFFSET_PERCENT_DISABLED to disable.

setItemAlignmentOffsetWithPadding

open fun setItemAlignmentOffsetWithPadding(withPadding: Boolean): Unit

Sets whether applies padding to item alignment when getItemAlignmentOffsetPercent() is 0 or 100.

When true: Applies start/top padding if getItemAlignmentOffsetPercent() is 0. Applies end/bottom padding if getItemAlignmentOffsetPercent() is 100. Does not apply padding if getItemAlignmentOffsetPercent() is neither 0 nor 100.

When false: does not apply padding

setItemAlignmentViewId

open fun setItemAlignmentViewId(viewId: Int): Unit

Sets the id of the view to align with. Use android.view.View#NO_ID (default) for the root RecyclerView.ViewHolder#itemView. Item alignment settings on BaseGridView are if ItemAlignmentFacet is provided by RecyclerView.ViewHolder or FacetProviderAdapter.

setItemMargin

open fun setItemMargin(margin: Int): Unit

Deprecated: use setItemSpacing(int)

Sets the spacing in pixels between two child items.

setItemSpacing

open fun setItemSpacing(spacing: Int): Unit

Sets the vertical and horizontal spacing in pixels between two child items.

Parameters
spacing Int: Vertical and horizontal spacing in pixels between two child items.

setLayoutEnabled

open fun setLayoutEnabled(layoutEnabled: Boolean): Unit

Enables or disables layout. All children will be removed when layout is disabled.

Parameters
layoutEnabled Boolean: True to enable layout, false otherwise.

setOnChildLaidOutListener

open fun setOnChildLaidOutListener(listener: OnChildLaidOutListener!): Unit

Registers a callback to be invoked when an item in BaseGridView has been laid out.

Parameters
listener OnChildLaidOutListener!: The listener to be invoked.

setOnChildSelectedListener

open fun setOnChildSelectedListener(listener: OnChildSelectedListener!): Unit

Registers a callback to be invoked when an item in BaseGridView has been selected. Note that the listener may be invoked when there is a layout pending on the view, affording the listener an opportunity to adjust the upcoming layout based on the selection state.

Parameters
listener OnChildSelectedListener!: The listener to be invoked.

setOnChildViewHolderSelectedListener

open fun setOnChildViewHolderSelectedListener(listener: OnChildViewHolderSelectedListener!): Unit

Registers a callback to be invoked when an item in BaseGridView has been selected. Note that the listener may be invoked when there is a layout pending on the view, affording the listener an opportunity to adjust the upcoming layout based on the selection state. This method will clear all existing listeners added by addOnChildViewHolderSelectedListener.

Parameters
listener OnChildViewHolderSelectedListener!: The listener to be invoked.

setOnKeyInterceptListener

open fun setOnKeyInterceptListener(listener: BaseGridView.OnKeyInterceptListener!): Unit

Sets the key intercept listener.

Parameters
listener BaseGridView.OnKeyInterceptListener!: The key intercept listener.

setOnMotionInterceptListener

open fun setOnMotionInterceptListener(listener: BaseGridView.OnMotionInterceptListener!): Unit

Sets the generic motion intercept listener.

Parameters
listener BaseGridView.OnMotionInterceptListener!: The motion intercept listener.

setOnTouchInterceptListener

open fun setOnTouchInterceptListener(listener: BaseGridView.OnTouchInterceptListener!): Unit

Sets the touch intercept listener.

Parameters
listener BaseGridView.OnTouchInterceptListener!: The touch intercept listener.

setOnUnhandledKeyListener

open fun setOnUnhandledKeyListener(listener: BaseGridView.OnUnhandledKeyListener!): Unit

Sets the unhandled key listener.

Parameters
listener BaseGridView.OnUnhandledKeyListener!: The unhandled key intercept listener.

setPruneChild

open fun setPruneChild(pruneChild: Boolean): Unit

Enables or disables pruning of children. Disable is useful during transition.

Parameters
pruneChild Boolean: True to prune children out side visible area, false to enable.

setRecyclerListener

open fun setRecyclerListener(listener: RecyclerView.RecyclerListener?): Unit

setSaveChildrenLimitNumber

fun setSaveChildrenLimitNumber(limitNumber: Int): Unit

Sets the limit number when getSaveChildrenPolicy() is SAVE_LIMITED_CHILD.

setSaveChildrenPolicy

fun setSaveChildrenPolicy(savePolicy: Int): Unit

Sets the policy for saving children.

Parameters
savePolicy Int: One of SAVE_NO_CHILD SAVE_ON_SCREEN_CHILD SAVE_LIMITED_CHILD SAVE_ALL_CHILD.

setScrollEnabled

open fun setScrollEnabled(scrollEnabled: Boolean): Unit

Enables or disables scrolling. Disable is useful during transition.

Parameters
scrollEnabled Boolean: True to enable scroll, false to disable.

setSelectedPosition

open fun setSelectedPosition(position: Int): Unit

Changes the selected item immediately without animation.

setSelectedPosition

open fun setSelectedPosition(position: Int, scrollExtra: Int): Unit

Changes the selected item immediately without animation, scrollExtra is applied in primary scroll direction. The scrollExtra will be kept until another setSelectedPosition or setSelectedPositionSmooth call.

setSelectedPosition

open fun setSelectedPosition(position: Int, task: ViewHolderTask!): Unit

Perform a task on ViewHolder at given position after scroll to it.

Parameters
position Int: Position of item in adapter.
task Int: Task to executed on the ViewHolder at a given position.

setSelectedPositionSmooth

open fun setSelectedPositionSmooth(position: Int): Unit

Changes the selected item and run an animation to scroll to the target position.

Parameters
position Int: Adapter position of the item to select.

setSelectedPositionSmooth

open fun setSelectedPositionSmooth(position: Int, task: ViewHolderTask!): Unit

Perform a task on ViewHolder at given position after smooth scrolling to it.

Parameters
position Int: Position of item in adapter.
task Int: Task to executed on the ViewHolder at a given position.

setVerticalMargin

open fun setVerticalMargin(margin: Int): Unit

Deprecated: Use setVerticalSpacing(int)

Sets the spacing in pixels between two child items vertically.

setVerticalSpacing

open fun setVerticalSpacing(spacing: Int): Unit

Sets the vertical spacing in pixels between two child items.

Parameters
spacing Int: Vertical spacing between two child items.

setWindowAlignment

open fun setWindowAlignment(windowAlignment: Int): Unit

Sets the method for focused item alignment in the view.

Parameters
windowAlignment Int: WINDOW_ALIGN_BOTH_EDGE, WINDOW_ALIGN_LOW_EDGE, WINDOW_ALIGN_HIGH_EDGE or WINDOW_ALIGN_NO_EDGE.

setWindowAlignmentOffset

open fun setWindowAlignmentOffset(offset: Int): Unit

Sets the offset in pixels for window alignment key line.

Parameters
offset Int: The number of pixels to offset. If the offset is positive, it is distance from low edge (see WINDOW_ALIGN_LOW_EDGE); if the offset is negative, the absolute value is distance from high edge (see WINDOW_ALIGN_HIGH_EDGE). Default value is 0.

setWindowAlignmentOffsetPercent

open fun setWindowAlignmentOffsetPercent(offsetPercent: Float): Unit

Sets the offset percent for window alignment key line in addition to .

Parameters
offsetPercent Float: Percentage to offset. E.g., 40 means 40% of the width from low edge. Use WINDOW_ALIGN_OFFSET_PERCENT_DISABLED to disable. Default value is 50.

setWindowAlignmentPreferKeyLineOverHighEdge

open fun setWindowAlignmentPreferKeyLineOverHighEdge(preferKeyLineOverHighEdge: Boolean): Unit

Returns whether prefer key line over high edge when WINDOW_ALIGN_HIGH_EDGE is used. When true, if there are very few items between high edge and key line, align items to key line instead of align items to high edge. Default value is true (aka prefer align to key line).

Parameters
preferKeyLineOverHighEdge Boolean: True to prefer key line over high edge, false otherwise.

setWindowAlignmentPreferKeyLineOverLowEdge

open fun setWindowAlignmentPreferKeyLineOverLowEdge(preferKeyLineOverLowEdge: Boolean): Unit

Sets whether prefer key line over low edge when WINDOW_ALIGN_LOW_EDGE is used. When true, if there are very few items between low edge and key line, align items to key line instead of align items to low edge. Default value is false (aka prefer align to low edge).

Parameters
preferKeyLineOverLowEdge Boolean: True to prefer key line over low edge, false otherwise.

smoothScrollToPosition

open fun smoothScrollToPosition(position: Int): Unit

Protected methods

dispatchGenericFocusedEvent

protected open fun dispatchGenericFocusedEvent(event: MotionEvent!): Boolean

onFocusChanged

protected open fun onFocusChanged(gainFocus: Boolean, direction: Int, previouslyFocusedRect: Rect!): Unit