BaseGridView


public abstract class BaseGridView extends RecyclerView

Known direct subclasses
HorizontalGridView

A android.view.ViewGroup that shows items in a horizontal scrolling list.

VerticalGridView

A android.view.ViewGroup that shows items in a vertically scrolling list.


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

Listener for intercepting key dispatch events.

Interface for receiving notification when BaseGridView has completed a full layout calculation.

Listener for intercepting generic motion dispatch events.

Listener for intercepting touch dispatch events.

Listener for intercepting unhandled key events.

Defines behavior of duration and interpolator for smoothScrollBy().

Constants

static final float

Value indicates that percent is not used.

static final int

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

static final int

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

static final int

Dont save states of any child views.

static final int

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

static final int

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

static final int

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

static final int

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

static final int

The focused item always stays in a key line location.

static final float

Value indicates that percent is not used.

Public methods

void

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

final void

Registers a callback to be invoked when the BaseGridView completes a full layout calculation.

void

Undo animateOut() and slide in child views.

void

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

boolean
boolean
@Nullable View
focusSearch(int direction)
int
getChildDrawingOrder(int childCount, int i)
int

This method is deprecated.

Use getHorizontalSpacing

int

Returns the horizontal spacing in pixels between two child items.

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.

int

Returns number of pixels to the end of low edge.

float

Returns the offset percent for item alignment in addition to getItemAlignmentOffset.

int

Returns the id of the view to align with, or NO_ID for the root itemView.

@Nullable BaseGridView.OnUnhandledKeyListener

Returns the unhandled key listener.

final int

Returns the limit used when when getSaveChildrenPolicy is SAVE_LIMITED_CHILD

final int

Returns the policy for saving children.

int

Returns the adapter position of selected item.

@Nullable BaseGridView.SmoothScrollByBehavior

Returns custom behavior for smoothScrollBy().

final int

When holding DPAD, DPAD events are generated faster than the grid view can scroll.

final float
int

This method is deprecated.

Use getVerticalSpacing

int

Returns the vertical spacing in pixels between two child items.

void
getViewSelectedOffsets(@NonNull View view, @NonNull int[] offsets)

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 getWindowAlignmentOffset.

boolean
boolean

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.

final boolean

Returns true if focus search is disabled.

boolean

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

boolean

Returns true if scrolling is enabled, false otherwise.

boolean

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

boolean

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

boolean
onRequestFocusInDescendants(
    int direction,
    @Nullable Rect previouslyFocusedRect
)
void
onRtlPropertiesChanged(int layoutDirection)

Notify layout manager that layout directionality has been updated

void

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

final void

Removes a callback to be invoked when the BaseGridView completes a full layout calculation.

void
void
removeViewAt(int index)
void
scrollToPosition(int position)

Convenience method to scroll to a certain position.

void
setAnimateChildLayout(boolean animateChildLayout)

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

void
setChildrenVisibility(int visibility)

Changes and overrides children's visibility.

void
setFocusDrawingOrderEnabled(boolean enabled)

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

final void
setFocusSearchDisabled(boolean disabled)

Disables or enables focus search.

void
setGravity(int gravity)

Sets the gravity used for child view positioning.

void
setHasOverlappingRendering(boolean hasOverlapping)
void
setHorizontalMargin(int margin)

This method is deprecated.

Use setHorizontalSpacing

void
setHorizontalSpacing(int spacing)

Sets the horizontal spacing in pixels between two child items.

void

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.

void

Sets number of pixels to the end of low edge.

void
setItemAlignmentOffsetPercent(float offsetPercent)

Sets the offset percent for item alignment in addition to getItemAlignmentOffset.

void
setItemAlignmentOffsetWithPadding(boolean withPadding)

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

void

Sets the id of the view to align with.

void
setItemMargin(int margin)

This method is deprecated.

use setItemSpacing

void
setItemSpacing(int spacing)

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

void
setLayoutEnabled(boolean layoutEnabled)

Enables or disables layout.

void

Set the LayoutManager that this RecyclerView will use.

void

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

void

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

void

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

void

Sets the key intercept listener.

void

Sets the generic motion intercept listener.

void

Sets the touch intercept listener.

void

Sets the unhandled key listener.

void
setPruneChild(boolean pruneChild)

Enables or disables pruning of children.

final void
setSaveChildrenLimitNumber(int limitNumber)

Sets the limit number when getSaveChildrenPolicy is SAVE_LIMITED_CHILD.

final void
setSaveChildrenPolicy(int savePolicy)

Sets the policy for saving children.

void
setScrollEnabled(boolean scrollEnabled)

Enables or disables scrolling.

void
setSelectedPosition(int position)

Changes the selected item immediately without animation.

void
setSelectedPosition(int position, int scrollExtra)

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

void

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

void

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

void

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

final void

Set custom behavior for smoothScrollBy().

final void
setSmoothScrollMaxPendingMoves(int maxPendingMoves)

When holding DPAD, DPAD events are generated faster than the grid view can scroll.

final void
setSmoothScrollSpeedFactor(float smoothScrollSpeedFactor)

Set factor of how slow the smoothScroller should run.

void
setVerticalMargin(int margin)

This method is deprecated.

Use setVerticalSpacing

void
setVerticalSpacing(int spacing)

Sets the vertical spacing in pixels between two child items.

void
setWindowAlignment(int windowAlignment)

Sets the method for focused item alignment in the view.

void

Sets the offset in pixels for window alignment key line.

void
setWindowAlignmentOffsetPercent(float offsetPercent)

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

void
setWindowAlignmentPreferKeyLineOverHighEdge(
    boolean preferKeyLineOverHighEdge
)

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

void
setWindowAlignmentPreferKeyLineOverLowEdge(
    boolean preferKeyLineOverLowEdge
)

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

void
smoothScrollBy(int dx, int dy)

Animate a scroll by the given amount of pixels along either axis.

void
smoothScrollBy(int dx, int dy, @Nullable Interpolator interpolator)

Animate a scroll by the given amount of pixels along either axis.

void
smoothScrollToPosition(int position)

Starts a smooth scroll to an adapter position.

Protected methods

boolean
void
onFocusChanged(
    boolean gainFocus,
    int direction,
    @Nullable Rect previouslyFocusedRect
)

Inherited Constants

From androidx.recyclerview.widget.RecyclerView
static final int
static final int
static final long
NO_ID = -1
static final int
static final int

The RecyclerView is currently being dragged by outside input such as user touch input.

static final int

The RecyclerView is not currently scrolling.

static final int

The RecyclerView is currently animating to a final position while not under outside control.

static final int

Constant for use with setScrollingTouchSlop.

static final int

Constant for use with setScrollingTouchSlop.

static final int
UNDEFINED_DURATION = -2147483648

Constant that represents that a duration has not been defined.

static final int
From android.view.View
static final int
static final int
static final int
static final int
static final int
static final int
static final Property<ViewFloat>
static final int
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE = "creditCardExpirationDate"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY = "creditCardExpirationDay"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH = "creditCardExpirationMonth"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR = "creditCardExpirationYear"
static final String
static final String
AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE = "creditCardSecurityCode"
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int
static final int
static final int
static final int
static final int
static final int
static final int[]
static final int[]
static final int[]
static final int[]
static final int
static final int
static final int
static final int
static final int
static final int
static final int
GONE = 8
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
KEEP_SCREEN_ON = 67108864
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
NO_ID = -1
static final int
static final int
static final int
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final float
static final float
static final float
static final float
static final float
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int[]
static final int[]
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final String
VIEW_LOG_TAG = "View"
static final int
static final int[]
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
From android.view.ViewGroup
static final int
static final int
static final int
static final int
static final int
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

Inherited methods

From androidx.core.view.NestedScrollingChild
abstract boolean
dispatchNestedPreScroll(
    int dx,
    int dy,
    @Nullable int[] consumed,
    @Nullable int[] offsetInWindow
)

Dispatch one step of a nested scroll in progress before this view consumes any portion of it.

abstract boolean
dispatchNestedScroll(
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    @Nullable int[] offsetInWindow
)

Dispatch one step of a nested scroll in progress.

abstract boolean

Begin a nestable scroll operation along the given axes.

From androidx.core.view.NestedScrollingChild2
abstract boolean
dispatchNestedPreScroll(
    int dx,
    int dy,
    @Nullable int[] consumed,
    @Nullable int[] offsetInWindow,
    int type
)

Dispatch one step of a nested scroll in progress before this view consumes any portion of it.

abstract boolean
dispatchNestedScroll(
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    @Nullable int[] offsetInWindow,
    int type
)

Dispatch one step of a nested scroll in progress.

abstract boolean

Returns true if this view has a nested scrolling parent for the given input type.

abstract boolean
startNestedScroll(int axes, int type)

Begin a nestable scroll operation along the given axes, for the given input type.

abstract void
stopNestedScroll(int type)

Stop a nested scroll in progress for the given input type.

From androidx.core.view.NestedScrollingChild3
abstract void
dispatchNestedScroll(
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    @Nullable int[] offsetInWindow,
    int type,
    @NonNull int[] consumed
)

Dispatch one step of a nested scroll in progress.

From androidx.recyclerview.widget.RecyclerView
void
addFocusables(ArrayList<View> views, int direction, int focusableMode)
void

Add an ItemDecoration to this RecyclerView.

void

Add an ItemDecoration to this RecyclerView.

void

Register a listener that will be notified whenever a child view is attached to or detached from RecyclerView.

void

Add an OnItemTouchListener to intercept touch events before they are dispatched to child views or this view's standard scrolling behavior.

void

Add a listener that will be notified of any changes in scroll state or position.

void

Register a listener that will be notified whenever a child view is recycled.

boolean
void

Removes all listeners that were added via addOnChildAttachStateChangeListener.

void

Remove all secondary listener that were notified of any changes in scroll state or position.

int

Compute the horizontal extent of the horizontal scrollbar's thumb within the horizontal range.

int

Compute the horizontal offset of the horizontal scrollbar's thumb within the horizontal range.

int

Compute the horizontal range that the horizontal scrollbar represents.

int

Compute the vertical extent of the vertical scrollbar's thumb within the vertical range.

int

Compute the vertical offset of the vertical scrollbar's thumb within the vertical range.

int

Compute the vertical range that the vertical scrollbar represents.</