BaseGridView
abstract class BaseGridView : RecyclerView
| kotlin.Any | ||||
| ↳ | android.view.View | |||
| ↳ | android.view.ViewGroup | |||
| ↳ | androidx.recyclerview.widget.RecyclerView | |||
| ↳ | androidx.leanback.widget.BaseGridView |
HorizontalGridView |
A |
VerticalGridView |
A |
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 types |
|---|
interface BaseGridView.OnKeyInterceptListenerListener for intercepting key dispatch events. |
interface BaseGridView.OnLayoutCompletedListenerInterface for receiving notification when BaseGridView has completed a full layout calculation. |
interface BaseGridView.OnMotionInterceptListenerListener for intercepting generic motion dispatch events. |
interface BaseGridView.OnTouchInterceptListenerListener for intercepting touch dispatch events. |
interface BaseGridView.OnUnhandledKeyListenerListener for intercepting unhandled key events. |
interface BaseGridView.SmoothScrollByBehaviorDefines behavior of duration and interpolator for smoothScrollBy(). |
Constants |
|
|---|---|
const Float |
Value indicates that percent is not used. |
const Int |
SAVE_ALL_CHILD = 3Save on screen views plus save off screen child views without any limitation. |
const Int |
Save on screen views plus save off screen child views states up to |
const Int |
SAVE_NO_CHILD = 0Dont save states of any child views. |
const Int |
Only save on screen child views, the states are lost when they become off screen. |
const Int |
The first item and last item are aligned with the two edges of the viewport. |
const Int |
The last item is aligned with the high edge of the viewport when navigating to the end of list. |
const Int |
The first item is aligned with the low edge of the viewport. |
const Int |
The focused item always stays in a key line location. |
const Float |
Value indicates that percent is not used. |
Public functions |
|
|---|---|
Unit |
Registers a callback to be invoked when an item in BaseGridView has been selected. |
Unit |
Registers a callback to be invoked when the BaseGridView completes a full layout calculation. |
Unit |
Undo animateOut() and slide in child views. |
Unit |
Temporarily slide out child views to bottom (for VerticalGridView) or end (for HorizontalGridView). |
Boolean |
dispatchKeyEvent(event: KeyEvent) |
Boolean |
dispatchTouchEvent(event: MotionEvent) |
View? |
focusSearch(direction: Int) |
Int |
getChildDrawingOrder(childCount: Int, i: Int) |
Int |
This function is deprecated. |
Int |
Returns the horizontal spacing in pixels between two child items. |
Int |
Gets the number of items to prefetch in |
Int |
Returns number of pixels to the end of low edge. |
Float |
Returns the offset percent for item alignment in addition to |
Int |
Returns the id of the view to align with, or |
BaseGridView.OnUnhandledKeyListener? |
Returns the unhandled key listener. |
Int |
Returns the limit used when when |
Int |
Returns the policy for saving children. |
Int |
Returns the adapter position of selected item. |
BaseGridView.SmoothScrollByBehavior? |
Returns custom behavior for smoothScrollBy(). |
Int |
When holding DPAD, DPAD events are generated faster than the grid view can scroll. |
Float |
|
Int |
This function is deprecated. |
Int |
Returns the vertical spacing in pixels between two child items. |
Unit |
getViewSelectedOffsets(view: View, offsets: IntArray)Returns the x/y offsets to final position from current position if the view is selected. |
Int |
Returns the method for focused item alignment in the view. |
Int |
Returns the offset in pixels for window alignment key line. |
Float |
Returns the offset percent for window alignment key line in addition to |
Boolean |
|
Boolean |
hasPreviousViewInSameRow(position: Int)Returns true if the view at the given position has a same row sibling in front of it. |
Boolean |
Returns true if an animation will run when a child changes size or when adding or removing a child. |
Boolean |
Returns true if draws selected child at last, false otherwise. |
Boolean |
Returns true if focus search is disabled. |
Boolean |
Returns true if applies padding to item alignment when |
Boolean |
Returns true if scrolling is enabled, false otherwise. |
Boolean |
Returns whether prefer key line over high edge when |
Boolean |
Returns whether prefer key line over low edge when |
Boolean |
onRequestFocusInDescendants(direction: Int, previouslyFocusedRect: Rect?) |
Unit |
onRtlPropertiesChanged(layoutDirection: Int)Notify layout manager that layout directionality has been updated |
Unit |
Remove the callback invoked when an item in BaseGridView has been selected. |
Unit |
Removes a callback to be invoked when the BaseGridView completes a full layout calculation. |
Unit |
removeView(view: View) |
Unit |
removeViewAt(index: Int) |
Unit |
scrollToPosition(position: Int)Convenience method to scroll to a certain position. |
Unit |
setAnimateChildLayout(animateChildLayout: Boolean)Sets whether ItemAnimator should run when a child changes size or when adding or removing a child. |
Unit |
setChildrenVisibility(visibility: Int)Changes and overrides children's visibility. |
Unit |
setFocusDrawingOrderEnabled(enabled: Boolean)Enables or disables the default "focus draw at last" order rule. |
Unit |
setFocusSearchDisabled(disabled: Boolean)Disables or enables focus search. |
Unit |
setGravity(gravity: Int)Sets the gravity used for child view positioning. |
Unit |
setHasOverlappingRendering(hasOverlapping: Boolean) |
Unit |
This function is deprecated. |
Unit |
setHorizontalSpacing(spacing: Int)Sets the horizontal spacing in pixels between two child items. |
Unit |
setInitialPrefetchItemCount(itemCount: Int)Sets the number of items to prefetch in |
Unit |
setItemAlignmentOffset(offset: Int)Sets number of pixels to the end of low edge. |
Unit |
setItemAlignmentOffsetPercent(offsetPercent: Float)Sets the offset percent for item alignment in addition to |
Unit |
setItemAlignmentOffsetWithPadding(withPadding: Boolean)Sets whether applies padding to item alignment when |
Unit |
setItemAlignmentViewId(viewId: Int)Sets the id of the view to align with. |
Unit |
This function is deprecated. use |
Unit |
setItemSpacing(spacing: Int)Sets the vertical and horizontal spacing in pixels between two child items. |
Unit |
setLayoutEnabled(layoutEnabled: Boolean)Enables or disables layout. |
Unit |
setLayoutManager(layout: RecyclerView.LayoutManager?)Set the |
Unit |
setOnChildLaidOutListener(listener: OnChildLaidOutListener?)Registers a callback to be invoked when an item in BaseGridView has been laid out. |
Unit |
setOnChildSelectedListener(listener: OnChildSelectedListener?)Registers a callback to be invoked when an item in BaseGridView has been selected. |
Unit |
Registers a callback to be invoked when an item in BaseGridView has been selected. |
Unit |
Sets the key intercept listener. |
Unit |
Sets the generic motion intercept listener. |
Unit |
Sets the touch intercept listener. |
Unit |
Sets the unhandled key listener. |
Unit |
setPruneChild(pruneChild: Boolean)Enables or disables pruning of children. |
Unit |
setSaveChildrenLimitNumber(limitNumber: Int)Sets the limit number when |
Unit |
setSaveChildrenPolicy(savePolicy: Int)Sets the policy for saving children. |
Unit |
setScrollEnabled(scrollEnabled: Boolean)Enables or disables scrolling. |
Unit |
setSelectedPosition(position: Int)Changes the selected item immediately without animation. |
Unit |
setSelectedPosition(position: Int, scrollExtra: Int)Changes the selected item immediately without animation, scrollExtra is applied in primary scroll direction. |
Unit |
setSelectedPosition(position: Int, task: ViewHolderTask?)Perform a task on ViewHolder at given position after scroll to it. |
Unit |
setSelectedPositionSmooth(position: Int)Changes the selected item and run an animation to scroll to the target position. |
Unit |
setSelectedPositionSmooth(position: Int, task: ViewHolderTask?)Perform a task on ViewHolder at given position after smooth scrolling to it. |
Unit |
Set custom behavior for smoothScrollBy(). |
Unit |
setSmoothScrollMaxPendingMoves(maxPendingMoves: Int)When holding DPAD, DPAD events are generated faster than the grid view can scroll. |
Unit |
setSmoothScrollSpeedFactor(smoothScrollSpeedFactor: Float)Set factor of how slow the smoothScroller should run. |
Unit |
This function is deprecated. |
Unit |
setVerticalSpacing(spacing: Int)Sets the vertical spacing in pixels between two child items. |
Unit |
setWindowAlignment(windowAlignment: Int)Sets the method for focused item alignment in the view. |
Unit |
setWindowAlignmentOffset(offset: Int)Sets the offset in pixels for window alignment key line. |
Unit |
setWindowAlignmentOffsetPercent(offsetPercent: Float)Sets the offset percent for window alignment key line in addition to |
Unit |
setWindowAlignmentPreferKeyLineOverHighEdge(Returns whether prefer key line over high edge when |
Unit |
setWindowAlignmentPreferKeyLineOverLowEdge(Sets whether prefer key line over low edge when |
Unit |
smoothScrollBy(dx: Int, dy: Int)Animate a scroll by the given amount of pixels along either axis. |
Unit |
smoothScrollBy(dx: Int, dy: Int, interpolator: Interpolator?)Animate a scroll by the given amount of pixels along either axis. |
Unit |
smoothScrollToPosition(position: Int)Starts a smooth scroll to an adapter position. |
Protected functions |
|
|---|---|
Boolean |
|
Unit |
onFocusChanged( |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Constants
ITEM_ALIGN_OFFSET_PERCENT_DISABLED
const val ITEM_ALIGN_OFFSET_PERCENT_DISABLED = -1.0f: Float
Value indicates that percent is not used.
SAVE_ALL_CHILD
const val SAVE_ALL_CHILD = 3: 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.
SAVE_LIMITED_CHILD
const val SAVE_LIMITED_CHILD = 2: Int
Save on screen views plus save off screen child views states up to getSaveChildrenLimitNumber.
SAVE_ON_SCREEN_CHILD
const val SAVE_ON_SCREEN_CHILD = 1: Int
Only save on screen child views, the states are lost when they become off screen.
WINDOW_ALIGN_BOTH_EDGE
const val WINDOW_ALIGN_BOTH_EDGE = 3: 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.
WINDOW_ALIGN_HIGH_EDGE
const val WINDOW_ALIGN_HIGH_EDGE = 2: 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 to control whether you prefer to align the items to key line or high edge. Default is preferring key line.
WINDOW_ALIGN_LOW_EDGE
const val WINDOW_ALIGN_LOW_EDGE = 1: 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 to control whether you prefer to align the items to key line or low edge. Default is preferring low edge.
WINDOW_ALIGN_NO_EDGE
const val WINDOW_ALIGN_NO_EDGE = 0: 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.
WINDOW_ALIGN_OFFSET_PERCENT_DISABLED
const val WINDOW_ALIGN_OFFSET_PERCENT_DISABLED = -1.0f: Float
Value indicates that percent is not used.
Public functions
addOnChildViewHolderSelectedListener
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. |
addOnLayoutCompletedListener
fun addOnLayoutCompletedListener(
listener: BaseGridView.OnLayoutCompletedListener
): Unit
Registers a callback to be invoked when the BaseGridView completes a full layout calculation.
| Parameters | |
|---|---|
listener: BaseGridView.OnLayoutCompletedListener |
The listener to be invoked. |
animateOut
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.
getHorizontalSpacing
fun getHorizontalSpacing(): Int
Returns the horizontal spacing in pixels between two child items.
| Returns | |
|---|---|
Int |
The Horizontal spacing in pixels between two child items. |
getInitialPrefetchItemCount
fun getInitialPrefetchItemCount(): Int
Gets the number of items to prefetch in collectInitialPrefetchPositions, which defines how many inner items should be prefetched when this GridView is nested inside another RecyclerView.
| Returns | |
|---|---|
Int |
number of items to prefetch. |
getItemAlignmentOffset
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.
| Returns | |
|---|---|
Int |
The number of pixels to the end of low edge. |
getItemAlignmentOffsetPercent
fun getItemAlignmentOffsetPercent(): Float
Returns the offset percent for item alignment in addition to getItemAlignmentOffset.
| Returns | |
|---|---|
Float |
Percentage to offset. E.g., 40 means 40% of the width from the low edge, or |
getItemAlignmentViewId
fun getItemAlignmentViewId(): Int
Returns the id of the view to align with, or NO_ID for the root itemView.
getOnUnhandledKeyListener
fun getOnUnhandledKeyListener(): BaseGridView.OnUnhandledKeyListener?
Returns the unhandled key listener.
| Returns | |
|---|---|
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.
| Returns | |
|---|---|
Int |
policy, one of |
getSelectedPosition
fun getSelectedPosition(): Int
Returns the adapter position of selected item.
| Returns | |
|---|---|
Int |
The adapter position of selected item. |
getSmoothScrollByBehavior
fun getSmoothScrollByBehavior(): BaseGridView.SmoothScrollByBehavior?
Returns custom behavior for smoothScrollBy().
| Returns | |
|---|---|
BaseGridView.SmoothScrollByBehavior? |
Custom behavior for SmoothScrollBy(). Null for default behavior. |
getSmoothScrollMaxPendingMoves
fun getSmoothScrollMaxPendingMoves(): Int
When holding DPAD, DPAD events are generated faster than the grid view can scroll. The grid view counts unhandled DPAD events and complete the movement after user release DPAD. If the value is set too high, the scrolling will last very long after DPAD is released. If the value is set too low, it may miss many DPAD events. The default value is 10. If app increases setSmoothScrollSpeedFactor, it may need decrease the max pending DPAD events to avoid scrolling too long after DPAD release.
| Returns | |
|---|---|
Int |
Maximum number of pending DPAD events to be remembered when smooth scroll cannot catch up speed of DPAD events being sent. |
getSmoothScrollSpeedFactor
fun getSmoothScrollSpeedFactor(): Float
| Returns | |
|---|---|
Float |
Factor of how slow the smoothScroller runs. Default value is 1f. |
getVerticalSpacing
fun getVerticalSpacing(): Int
Returns the vertical spacing in pixels between two child items.
| Returns | |
|---|---|
Int |
The vertical spacing in pixels between two child items. |
getViewSelectedOffsets
fun getViewSelectedOffsets(view: View, offsets: IntArray): Unit
Returns the x/y offsets to final position from current position if the view is selected.
getWindowAlignment
fun getWindowAlignment(): Int
Returns the method for focused item alignment in the view.
getWindowAlignmentOffset
fun getWindowAlignmentOffset(): Int
Returns the offset in pixels for window alignment key line.
| Returns | |
|---|---|
Int |
The number of pixels to offset. If the offset is positive, it is distance from low edge (see |
getWindowAlignmentOffsetPercent
fun getWindowAlignmentOffsetPercent(): Float
Returns the offset percent for window alignment key line in addition to getWindowAlignmentOffset.
| Returns | |
|---|---|
Float |
Percentage to offset. E.g., 40 means 40% of the width from the low edge, or |
hasPreviousViewInSameRow
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. |
| Returns | |
|---|---|
Boolean |
True if the view at the given position has a same row sibling in front of it. |
isChildLayoutAnimated
fun isChildLayoutAnimated(): Boolean
Returns true if an animation will run when a child changes size or when adding or removing a child.
| Returns | |
|---|---|
Boolean |
True if ItemAnimator is enabled, false otherwise. |
isFocusDrawingOrderEnabled
fun isFocusDrawingOrderEnabled(): Boolean
Returns true if draws selected child at last, false otherwise. Default is enabled.
| Returns | |
|---|---|
Boolean |
True if draws selected child at last, false otherwise. |
isFocusSearchDisabled
fun isFocusSearchDisabled(): Boolean
Returns true if focus search is disabled.
| Returns | |
|---|---|
Boolean |
True if focus search is disabled. |
isItemAlignmentOffsetWithPadding
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
fun isScrollEnabled(): Boolean
Returns true if scrolling is enabled, false otherwise.
| Returns | |
|---|---|
Boolean |
True if scrolling is enabled, false otherwise. |
isWindowAlignmentPreferKeyLineOverHighEdge
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).
| Returns | |
|---|---|
Boolean |
True to prefer key line over high edge, false otherwise. |
isWindowAlignmentPreferKeyLineOverLowEdge
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).
| Returns | |
|---|---|
Boolean |
True to prefer key line over low edge, false otherwise. |
onRequestFocusInDescendants
fun onRequestFocusInDescendants(direction: Int, previouslyFocusedRect: Rect?): Boolean
onRtlPropertiesChanged
fun onRtlPropertiesChanged(layoutDirection: Int): Unit
Notify layout manager that layout directionality has been updated
removeOnChildViewHolderSelectedListener
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. |
removeOnLayoutCompletedListener
fun removeOnLayoutCompletedListener(
listener: BaseGridView.OnLayoutCompletedListener
): Unit
Removes a callback to be invoked when the BaseGridView completes a full layout calculation.
| Parameters | |
|---|---|
listener: BaseGridView.OnLayoutCompletedListener |
The listener to be invoked. |
scrollToPosition
fun scrollToPosition(position: Int): Unit
Convenience method to scroll to a certain position. RecyclerView does not implement scrolling logic, rather forwards the call to scrollToPosition
| Parameters | |
|---|---|
position: Int |
Scroll to this adapter position |
| See also | |
|---|---|
scrollToPosition |
setAnimateChildLayout
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
fun setChildrenVisibility(visibility: Int): Unit
Changes and overrides children's visibility.
| Parameters | |
|---|---|
visibility: Int |
See |
setFocusDrawingOrderEnabled
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
fun setGravity(gravity: Int): Unit
Sets the gravity used for child view positioning. Defaults to GRAVITY_TOP|GRAVITY_START.
| Parameters | |
|---|---|
gravity: Int |
setHasOverlappingRendering
fun setHasOverlappingRendering(hasOverlapping: Boolean): Unit
funsetHorizontalMargin(margin: Int): Unit
Sets the spacing in pixels between two child items horizontally.
setHorizontalSpacing
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
fun setInitialPrefetchItemCount(itemCount: Int): Unit
Sets the number of items to prefetch in collectInitialPrefetchPositions, 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
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
fun setItemAlignmentOffsetPercent(offsetPercent: Float): Unit
Sets the offset percent for item alignment in addition to getItemAlignmentOffset. 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 |
setItemAlignmentOffsetWithPadding
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
fun setItemAlignmentViewId(viewId: Int): Unit
Sets the id of the view to align with. Use NO_ID (default) for the root itemView. Item alignment settings on BaseGridView are if ItemAlignmentFacet is provided by RecyclerView.ViewHolder or FacetProviderAdapter.
setItemSpacing
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
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. |
setLayoutManager
fun setLayoutManager(layout: RecyclerView.LayoutManager?): Unit
Set the LayoutManager that this RecyclerView will use.
In contrast to other adapter-backed views such as android.widget.ListView or android.widget.GridView, RecyclerView allows client code to provide custom layout arrangements for child views. These arrangements are controlled by the LayoutManager. A LayoutManager must be provided for RecyclerView to function.
Several default strategies are provided for common uses such as lists and grids.
| Parameters | |
|---|---|
layout: RecyclerView.LayoutManager? |
LayoutManager to use |
setOnChildLaidOutListener
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
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
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
fun setOnKeyInterceptListener(
listener: BaseGridView.OnKeyInterceptListener?
): Unit
Sets the key intercept listener.
| Parameters | |
|---|---|
listener: BaseGridView.OnKeyInterceptListener? |
The key intercept listener. |
setOnMotionInterceptListener
fun setOnMotionInterceptListener(
listener: BaseGridView.OnMotionInterceptListener?
): Unit
Sets the generic motion intercept listener.
| Parameters | |
|---|---|
listener: BaseGridView.OnMotionInterceptListener? |
The motion intercept listener. |
setOnTouchInterceptListener
fun setOnTouchInterceptListener(
listener: BaseGridView.OnTouchInterceptListener?
): Unit
Sets the touch intercept listener.
| Parameters | |
|---|---|
listener: BaseGridView.OnTouchInterceptListener? |
The touch intercept listener. |
setOnUnhandledKeyListener
fun setOnUnhandledKeyListener(
listener: BaseGridView.OnUnhandledKeyListener?
): Unit
Sets the unhandled key listener.
| Parameters | |
|---|---|
listener: BaseGridView.OnUnhandledKeyListener? |
The unhandled key intercept listener. |
setPruneChild
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. |
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 |
setScrollEnabled
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
fun setSelectedPosition(position: Int): Unit
Changes the selected item immediately without animation.
setSelectedPosition
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
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: ViewHolderTask? |
Task to executed on the ViewHolder at a given position. |
setSelectedPositionSmooth
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
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: ViewHolderTask? |
Task to executed on the ViewHolder at a given position. |
setSmoothScrollByBehavior
fun setSmoothScrollByBehavior(
behavior: BaseGridView.SmoothScrollByBehavior?
): Unit
Set custom behavior for smoothScrollBy().
| Parameters | |
|---|---|
behavior: BaseGridView.SmoothScrollByBehavior? |
Custom behavior of SmoothScrollBy(). Null for default behavior. |
setSmoothScrollMaxPendingMoves
fun setSmoothScrollMaxPendingMoves(maxPendingMoves: Int): Unit
When holding DPAD, DPAD events are generated faster than the grid view can scroll. The grid view counts unhandled DPAD events and completes the movement after user release DPAD. If the value is set too high, the scrolling will last very long after DPAD is released. If the value is set too low, it may miss many DPAD events. The default value is 10. If app increases setSmoothScrollSpeedFactor, it may need decrease the max pending DPAD events to avoid scrolling too long after DPAD release.
| Parameters | |
|---|---|
maxPendingMoves: Int |
Maximum number of pending DPAD events to be remembered. |
setSmoothScrollSpeedFactor
fun setSmoothScrollSpeedFactor(smoothScrollSpeedFactor: Float): Unit
Set factor of how slow the smoothScroller should run. For example when set to 2f, the smooth scroller is twice slower. The value is 1f by default.
| Parameters | |
|---|---|
smoothScrollSpeedFactor: Float |
Factor of how slow the smooth scroll is. |
funsetVerticalMargin(margin: Int): Unit
Sets the spacing in pixels between two child items vertically.
setVerticalSpacing
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
fun setWindowAlignment(windowAlignment: Int): Unit
Sets the method for focused item alignment in the view.
| Parameters | |
|---|---|
windowAlignment: Int |
|
setWindowAlignmentOffset
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 |
setWindowAlignmentOffsetPercent
fun setWindowAlignmentOffsetPercent(offsetPercent: Float): Unit
Sets the offset percent for window alignment key line in addition to getWindowAlignmentOffset.
| Parameters | |
|---|---|
offsetPercent: Float |
Percentage to offset. E.g., 40 means 40% of the width from low edge. Use |
setWindowAlignmentPreferKeyLineOverHighEdge
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
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. |
smoothScrollBy
fun smoothScrollBy(dx: Int, dy: Int): Unit
Animate a scroll by the given amount of pixels along either axis.
smoothScrollBy
fun smoothScrollBy(dx: Int, dy: Int, interpolator: Interpolator?): Unit
Animate a scroll by the given amount of pixels along either axis.
| Parameters | |
|---|---|
dx: Int |
Pixels to scroll horizontally |
dy: Int |
Pixels to scroll vertically |
interpolator: Interpolator? |
|
smoothScrollToPosition
fun smoothScrollToPosition(position: Int): Unit
Starts a smooth scroll to an adapter position.
To support smooth scrolling, you must override smoothScrollToPosition and create a SmoothScroller.
LayoutManager is responsible for creating the actual scroll action. If you want to provide a custom smooth scroll logic, override smoothScrollToPosition in your LayoutManager.
| Parameters | |
|---|---|
position: Int |
The adapter position to scroll to |
| See also | |
|---|---|
smoothScrollToPosition |
Protected functions
onFocusChanged
protected fun onFocusChanged(
gainFocus: Boolean,
direction: Int,
previouslyFocusedRect: Rect?
): Unit