Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 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 touch dispatch events.

abstract

Listener for intercepting generic motion dispatch events.

abstract

Listener for intercepting key dispatch events.

abstract

Constants
static Int

The first item is aligned with the low edge 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 and last item are aligned with the two edges of the viewport.

static Int

The focused item always stays in a key line location.

static Float

Value indicates that percent is not used.

static Float

Value indicates that percent is not used.

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

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

static Int

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

Inherited constants
Public methods
open Unit
getViewSelectedOffsets(view: View!, offsets: IntArray!)

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

Unit

Disables or enables focus search.

open Unit

Unit

Sets the limit number when getSaveChildrenPolicy() is SAVE_LIMITED_CHILD.

open Unit

Sets the unhandled key listener.

open Unit

Sets the horizontal spacing in pixels between two child items.

open Unit

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

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

open Unit
setScrollEnabled(scrollEnabled: Boolean)

Enables or disables scrolling.

open Unit

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

open Unit

Sets the generic motion intercept listener.

open Unit
setGravity(gravity: Int)

Sets the gravity used for child view positioning.

open View!
focusSearch(direction: Int)

open Unit

Changes and overrides children's visibility.

open Unit

Sets the vertical spacing in pixels between two child items.

open BaseGridView.OnUnhandledKeyListener!

Returns the unhandled key listener.

open Unit
setItemMargin(margin: Int)

Sets the spacing in pixels between two child items.

open Boolean

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

open Boolean

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

open Unit

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

open Unit
scrollToPosition(position: Int)

open Int

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

open Unit

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

open Int

Returns the vertical spacing in pixels between two child items.

open Int

Returns the adapter position of selected item.

open Boolean

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

open Int

Returns the spacing in pixels between two child items horizontally.

open Float

Returns the offset percent for item alignment in addition to .

open Unit

Sets the offset in pixels for window alignment key line.

open Unit
setAnimateChildLayout(animateChildLayout: Boolean)

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

open Unit
setLayoutEnabled(layoutEnabled: Boolean)

Enables or disables layout.

open Unit
setItemSpacing(spacing: Int)

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

open Unit

Sets the touch intercept listener.

open Unit

Int

Returns the policy for saving children.

open Unit

Sets the key intercept listener.

open Unit

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

open Int

Returns the offset in pixels for window alignment key line.

open Unit

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

open Float

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

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 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 Unit
setWindowAlignment(windowAlignment: Int)

Sets the method for focused item alignment in the view.

open Unit

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

open Boolean

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

open Unit

Sets the spacing in pixels between two child items horizontally.

open Unit

Sets the spacing in pixels between two child items vertically.

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

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

open Unit
onRtlPropertiesChanged(layoutDirection: Int)

Notify layout manager that layout directionality has been updated

open Boolean

Returns true if scrolling is enabled, false otherwise.

open Unit

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

Boolean

Returns true if focus search is disabled.

Unit

Sets the policy for saving children.

open Int

Returns the method for focused item alignment in the view.

open Boolean

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

open Boolean

open Unit
removeView(view: View!)

open Unit

Undo animateOut() and slide in child views.

open Unit
removeViewAt(index: Int)

open Unit

open Int

Returns number of pixels to the end of low edge.

open Boolean

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

open Int

Returns the spacing in pixels between two child items vertically.

open Unit
setPruneChild(pruneChild: Boolean)

Enables or disables pruning of children.

open Unit

Sets the id of the view to align with.

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 Boolean

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

open Int

Returns the horizontal spacing in pixels between two child items.

Int

Returns the limit used when when getSaveChildrenPolicy() is SAVE_LIMITED_CHILD

open Unit

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

open Unit

Sets the offset percent for item alignment in addition to .

open Boolean

open Unit

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

open Unit

Sets number of pixels to the end of low edge.

Protected methods
open Boolean

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

Inherited functions

Constants

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

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

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

Public methods

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.

setFocusSearchDisabled

fun setFocusSearchDisabled(disabled: Boolean): Unit

Disables or enables focus search.

Parameters
disabled Boolean: True to disable focus search, 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.

setOnUnhandledKeyListener

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

Sets the unhandled key listener.

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

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.

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.

getChildDrawingOrder

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

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.

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.

setOnMotionInterceptListener

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

Sets the generic motion intercept listener.

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

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

focusSearch

open fun focusSearch(direction: Int): View!

setChildrenVisibility

open fun setChildrenVisibility(visibility: Int): Unit

Changes and overrides children's visibility.

Parameters
visibility Int: See View#getVisibility().

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.

getOnUnhandledKeyListener

open fun getOnUnhandledKeyListener(): BaseGridView.OnUnhandledKeyListener!

Returns the unhandled key listener.

Return
BaseGridView.OnUnhandledKeyListener!: The unhandled key listener.

setItemMargin

open fun setItemMargin(margin: Int): Unit

Sets the spacing in pixels between two child items.

dispatchKeyEvent

open fun dispatchKeyEvent(event: KeyEvent!): Boolean

onRequestFocusInDescendants

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

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

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.

scrollToPosition

open fun scrollToPosition(position: Int): Unit

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.

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

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.

getSelectedPosition

open fun getSelectedPosition(): Int

Returns the adapter position of selected item.

Return
Int: The adapter position of selected item.

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.

getHorizontalMargin

open fun getHorizontalMargin(): Int

Returns the spacing in pixels between two child items horizontally.

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.

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.

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.

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.

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.

setOnTouchInterceptListener

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

Sets the touch intercept listener.

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

setHasOverlappingRendering

open fun setHasOverlappingRendering(hasOverlapping: Boolean): Unit

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.

setOnKeyInterceptListener

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

Sets the key intercept listener.

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

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.

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.

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.

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.

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.

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.

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.

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.

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.

setHorizontalMargin

open fun setHorizontalMargin(margin: Int): Unit

Sets the spacing in pixels between two child items horizontally.

setVerticalMargin

open fun setVerticalMargin(margin: Int): Unit

Sets the spacing in pixels between two child items vertically.

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

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.

onRtlPropertiesChanged

open fun onRtlPropertiesChanged(layoutDirection: Int): Unit

Notify layout manager that layout directionality has been updated

isScrollEnabled

open fun isScrollEnabled(): Boolean

Returns true if scrolling is enabled, false otherwise.

Return
Boolean: True if scrolling is enabled, 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.

isFocusSearchDisabled

fun isFocusSearchDisabled(): Boolean

Returns true if focus search is disabled.

Return
Boolean: True if focus search is disabled.

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.

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.

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.

hasOverlappingRendering

open fun hasOverlappingRendering(): Boolean

removeView

open fun removeView(view: View!): Unit

animateIn

open fun animateIn(): Unit

Undo animateOut() and slide in child views.

removeViewAt

open fun removeViewAt(index: Int): Unit

smoothScrollToPosition

open fun smoothScrollToPosition(position: Int): Unit

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.

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.

getVerticalMargin

open fun getVerticalMargin(): Int

Returns the spacing in pixels between two child items vertically.

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.

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.

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.

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.

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.

getSaveChildrenLimitNumber

fun getSaveChildrenLimitNumber(): Int

Returns the limit used when when getSaveChildrenPolicy() is SAVE_LIMITED_CHILD

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.

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.

dispatchTouchEvent

open fun dispatchTouchEvent(event: MotionEvent!): Boolean

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.

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.

Protected methods

dispatchGenericFocusedEvent

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

onFocusChanged

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