belongs to Maven artifact com.android.support:leanback-v17:28.0.0-alpha1
BaseGridView
public
abstract
class
BaseGridView
extends RecyclerView
java.lang.Object | ||||
↳ | android.view.View | |||
↳ | android.view.ViewGroup | |||
↳ | android.support.v7.widget.RecyclerView | |||
↳ | android.support.v17.leanback.widget.BaseGridView |
Known Direct Subclasses |
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 | |
---|---|
interface |
BaseGridView.OnKeyInterceptListener
Listener for intercepting key dispatch events. |
interface |
BaseGridView.OnMotionInterceptListener
Listener for intercepting generic motion dispatch events. |
interface |
BaseGridView.OnTouchInterceptListener
Listener for intercepting touch dispatch events. |
interface |
BaseGridView.OnUnhandledKeyListener
|
Inherited XML attributes | |
---|---|
From
class
android.support.v7.widget.RecyclerView
|
Constants | |
---|---|
float |
ITEM_ALIGN_OFFSET_PERCENT_DISABLED
Value indicates that percent is not used. |
int |
SAVE_ALL_CHILD
Save on screen views plus save off screen child views without any limitation. |
int |
SAVE_LIMITED_CHILD
Save on screen views plus save off screen child views states up to
|
int |
SAVE_NO_CHILD
Dont save states of any child views. |
int |
SAVE_ON_SCREEN_CHILD
Only save on screen child views, the states are lost when they become off screen. |
int |
WINDOW_ALIGN_BOTH_EDGE
The first item and last item are aligned with the two edges of the viewport. |
int |
WINDOW_ALIGN_HIGH_EDGE
The last item is aligned with the high edge of the viewport when navigating to the end of list. |
int |
WINDOW_ALIGN_LOW_EDGE
The first item is aligned with the low edge of the viewport. |
int |
WINDOW_ALIGN_NO_EDGE
The focused item always stays in a key line location. |
float |
WINDOW_ALIGN_OFFSET_PERCENT_DISABLED
Value indicates that percent is not used. |
Inherited constants |
---|
From
class
android.support.v7.widget.RecyclerView
|
From
class
android.view.ViewGroup
|
From
class
android.view.View
|
Inherited fields |
---|
From
class
android.view.View
|
Public methods | |
---|---|
void
|
addOnChildViewHolderSelectedListener(OnChildViewHolderSelectedListener listener)
Registers a callback to be invoked when an item in BaseGridView has been selected. |
void
|
animateIn()
Undo animateOut() and slide in child views. |
void
|
animateOut()
Temporarily slide out child views to bottom (for VerticalGridView) or end (for HorizontalGridView). |
boolean
|
dispatchKeyEvent(KeyEvent event)
|
boolean
|
dispatchTouchEvent(MotionEvent event)
|
View
|
focusSearch(int direction)
|
int
|
getChildDrawingOrder(int childCount, int i)
|
int
|
getHorizontalMargin()
This method was deprecated
in API level 26.1.0.
Use |
int
|
getHorizontalSpacing()
Returns the horizontal spacing in pixels between two child items. |
int
|
getInitialPrefetchItemCount()
Gets the number of items to prefetch in
|
int
|
getItemAlignmentOffset()
Returns number of pixels to the end of low edge. |
float
|
getItemAlignmentOffsetPercent()
Returns the offset percent for item alignment in addition to |
int
|
getItemAlignmentViewId()
Returns the id of the view to align with, or |
BaseGridView.OnUnhandledKeyListener
|
getOnUnhandledKeyListener()
Returns the unhandled key listener. |
final
int
|
getSaveChildrenLimitNumber()
Returns the limit used when when |
final
int
|
getSaveChildrenPolicy()
Returns the policy for saving children. |
int
|
getSelectedPosition()
Returns the adapter position of selected item. |
int
|
getVerticalMargin()
This method was deprecated
in API level 26.1.0.
Use |
int
|
getVerticalSpacing()
Returns the vertical spacing in pixels between two child items. |
void
|
getViewSelectedOffsets(View view, int[] offsets)
Returns the x/y offsets to final position from current position if the view is selected. |
int
|
getWindowAlignment()
Returns the method for focused item alignment in the view. |
int
|
getWindowAlignmentOffset()
Returns the offset in pixels for window alignment key line. |
float
|
getWindowAlignmentOffsetPercent()
Returns the offset percent for window alignment key line in addition to
|
boolean
|
hasOverlappingRendering()
|
boolean
|
hasPreviousViewInSameRow(int position)
Returns true if the view at the given position has a same row sibling in front of it. |
boolean
|
isChildLayoutAnimated()
Returns true if an animation will run when a child changes size or when adding or removing a child. |
boolean
|
isFocusDrawingOrderEnabled()
Returns true if draws selected child at last, false otherwise. |
final
boolean
|
isFocusSearchDisabled()
Returns true if focus search is disabled. |
boolean
|
isItemAlignmentOffsetWithPadding()
Returns true if applies padding to item alignment when
|
boolean
|
isScrollEnabled()
Returns true if scrolling is enabled, false otherwise. |
boolean
|
isWindowAlignmentPreferKeyLineOverHighEdge()
Returns whether prefer key line over high edge when |
boolean
|
isWindowAlignmentPreferKeyLineOverLowEdge()
Returns whether prefer key line over low edge when |
boolean
|
onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect)
|
void
|
onRtlPropertiesChanged(int layoutDirection)
Notify layout manager that layout directionality has been updated |
void
|
removeOnChildViewHolderSelectedListener(OnChildViewHolderSelectedListener listener)
Remove the callback invoked when an item in BaseGridView has been selected. |
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 was deprecated
in API level 26.1.0.
Use |
void
|
setHorizontalSpacing(int spacing)
Sets the horizontal spacing in pixels between two child items. |
void
|
setInitialPrefetchItemCount(int itemCount)
Sets the number of items to prefetch in
|
void
|
setItemAlignmentOffset(int offset)
Sets number of pixels to the end of low edge. |
void
|
setItemAlignmentOffsetPercent(float offsetPercent)
Sets the offset percent for item alignment in addition to |
void
|
setItemAlignmentOffsetWithPadding(boolean withPadding)
Sets whether applies padding to item alignment when |
void
|
setItemAlignmentViewId(int viewId)
Sets the id of the view to align with. |
void
|
setItemMargin(int margin)
This method was deprecated
in API level 26.1.0.
use |
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
|
setOnChildLaidOutListener(OnChildLaidOutListener listener)
Registers a callback to be invoked when an item in BaseGridView has been laid out. |
void
|
setOnChildSelectedListener(OnChildSelectedListener listener)
Registers a callback to be invoked when an item in BaseGridView has been selected. |
void
|
setOnChildViewHolderSelectedListener(OnChildViewHolderSelectedListener listener)
Registers a callback to be invoked when an item in BaseGridView has been selected. |
void
|
setOnKeyInterceptListener(BaseGridView.OnKeyInterceptListener listener)
Sets the key intercept listener. |
void
|
setOnMotionInterceptListener(BaseGridView.OnMotionInterceptListener listener)
Sets the generic motion intercept listener. |
void
|
setOnTouchInterceptListener(BaseGridView.OnTouchInterceptListener listener)
Sets the touch intercept listener. |
void
|
setOnUnhandledKeyListener(BaseGridView.OnUnhandledKeyListener listener)
Sets the unhandled key listener. |
void
|
setPruneChild(boolean pruneChild)
Enables or disables pruning of children. |
void
|
setRecyclerListener(RecyclerView.RecyclerListener listener)
Register a listener that will be notified whenever a child view is recycled. |
final
void
|
setSaveChildrenLimitNumber(int limitNumber)
Sets the limit number when |
final
void
|
setSaveChildrenPolicy(int savePolicy)
Sets the policy for saving children. |
void
|
setScrollEnabled(boolean scrollEnabled)
Enables or disables scrolling. |
void
|
setSelectedPosition(int position, ViewHolderTask task)
Perform a task on ViewHolder at given position after scroll to it. |
void
|
setSelectedPosition(int position, int scrollExtra)
Changes the selected item immediately without animation, scrollExtra is applied in primary scroll direction. |
void
|
setSelectedPosition(int position)
Changes the selected item immediately without animation. |
void
|
setSelectedPositionSmooth(int position)
Changes the selected item and run an animation to scroll to the target position. |
void
|
setSelectedPositionSmooth(int position, ViewHolderTask task)
Perform a task on ViewHolder at given position after smooth scrolling to it. |
void
|
setVerticalMargin(int margin)
This method was deprecated
in API level 26.1.0.
Use |
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
|
setWindowAlignmentOffset(int offset)
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 |
void
|
setWindowAlignmentPreferKeyLineOverHighEdge(boolean preferKeyLineOverHighEdge)
Returns whether prefer key line over high edge when |
void
|
setWindowAlignmentPreferKeyLineOverLowEdge(boolean preferKeyLineOverLowEdge)
Sets whether prefer key line over low edge when |
void
|
smoothScrollToPosition(int position)
Starts a smooth scroll to an adapter position. |
Protected methods | |
---|---|
boolean
|
dispatchGenericFocusedEvent(MotionEvent event)
|
void
|
onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect)
|
Inherited methods | |
---|---|
From
class
android.support.v7.widget.RecyclerView
| |
From
class
android.view.ViewGroup
| |
From
class
android.view.View
| |
From
class
java.lang.Object
| |
From
interface
android.support.v4.view.ScrollingView
| |
From
interface
android.support.v4.view.NestedScrollingChild2
| |
From
interface
android.view.ViewParent
| |
From
interface
android.view.ViewManager
| |
From
interface
android.graphics.drawable.Drawable.Callback
| |
From
interface
android.view.KeyEvent.Callback
| |
From
interface
android.view.accessibility.AccessibilityEventSource
| |
From
interface
android.support.v4.view.NestedScrollingChild
|
Constants
ITEM_ALIGN_OFFSET_PERCENT_DISABLED
float ITEM_ALIGN_OFFSET_PERCENT_DISABLED
Value indicates that percent is not used.
Constant Value: -1.0
SAVE_ALL_CHILD
int SAVE_ALL_CHILD
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.
Constant Value: 3 (0x00000003)
SAVE_LIMITED_CHILD
int SAVE_LIMITED_CHILD
Save on screen views plus save off screen child views states up to
getSaveChildrenLimitNumber()
.
Constant Value: 2 (0x00000002)
SAVE_NO_CHILD
int SAVE_NO_CHILD
Dont save states of any child views.
Constant Value: 0 (0x00000000)
SAVE_ON_SCREEN_CHILD
int SAVE_ON_SCREEN_CHILD
Only save on screen child views, the states are lost when they become off screen.
Constant Value: 1 (0x00000001)
WINDOW_ALIGN_BOTH_EDGE
int WINDOW_ALIGN_BOTH_EDGE
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.
Constant Value: 3 (0x00000003)
WINDOW_ALIGN_HIGH_EDGE
int WINDOW_ALIGN_HIGH_EDGE
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.
Constant Value: 2 (0x00000002)
WINDOW_ALIGN_LOW_EDGE
int WINDOW_ALIGN_LOW_EDGE
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.
Constant Value: 1 (0x00000001)
WINDOW_ALIGN_NO_EDGE
int WINDOW_ALIGN_NO_EDGE
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.
Constant Value: 0 (0x00000000)
WINDOW_ALIGN_OFFSET_PERCENT_DISABLED
float WINDOW_ALIGN_OFFSET_PERCENT_DISABLED
Value indicates that percent is not used.
Constant Value: -1.0
Public methods
addOnChildViewHolderSelectedListener
void addOnChildViewHolderSelectedListener (OnChildViewHolderSelectedListener listener)
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.
|
animateOut
void animateOut ()
Temporarily slide out child views to bottom (for VerticalGridView) or end
(for HorizontalGridView). Layout and scrolling will be suppressed until
animateIn()
is called.
dispatchKeyEvent
boolean dispatchKeyEvent (KeyEvent event)
Parameters | |
---|---|
event |
KeyEvent |
Returns | |
---|---|
boolean |
dispatchTouchEvent
boolean dispatchTouchEvent (MotionEvent event)
Parameters | |
---|---|
event |
MotionEvent |
Returns | |
---|---|
boolean |
getChildDrawingOrder
int getChildDrawingOrder (int childCount, int i)
Parameters | |
---|---|
childCount |
int |
i |
int |
Returns | |
---|---|
int |
getHorizontalMargin
int getHorizontalMargin ()
This method was deprecated
in API level 26.1.0.
Use getHorizontalSpacing()
Returns the spacing in pixels between two child items horizontally.
Returns | |
---|---|
int |
getHorizontalSpacing
int getHorizontalSpacing ()
Returns the horizontal spacing in pixels between two child items.
Returns | |
---|---|
int |
The Horizontal spacing in pixels between two child items. |
getInitialPrefetchItemCount
int getInitialPrefetchItemCount ()
Gets the number of items to prefetch in
collectInitialPrefetchPositions(int, RecyclerView.LayoutManager.LayoutPrefetchRegistry)
,
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
int getItemAlignmentOffset ()
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
float getItemAlignmentOffsetPercent ()
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 ITEM_ALIGN_OFFSET_PERCENT_DISABLED if
disabled. Default value is 50.
|
getItemAlignmentViewId
int getItemAlignmentViewId ()
Returns the id of the view to align with, or NO_ID
for the root
itemView
.
Returns | |
---|---|
int |
The id of the view to align with, or NO_ID for the root
itemView .
|
getOnUnhandledKeyListener
BaseGridView.OnUnhandledKeyListener getOnUnhandledKeyListener ()
Returns the unhandled key listener.
Returns | |
---|---|
BaseGridView.OnUnhandledKeyListener |
The unhandled key listener. |
getSaveChildrenLimitNumber
int getSaveChildrenLimitNumber ()
Returns the limit used when when getSaveChildrenPolicy()
is
SAVE_LIMITED_CHILD
Returns | |
---|---|
int |
getSaveChildrenPolicy
int getSaveChildrenPolicy ()
Returns the policy for saving children.
Returns | |
---|---|
int |
policy, one of SAVE_NO_CHILD
SAVE_ON_SCREEN_CHILD SAVE_LIMITED_CHILD SAVE_ALL_CHILD .
|
getSelectedPosition
int getSelectedPosition ()
Returns the adapter position of selected item.
Returns | |
---|---|
int |
The adapter position of selected item. |
getVerticalMargin
int getVerticalMargin ()
This method was deprecated
in API level 26.1.0.
Use getVerticalSpacing()
Returns the spacing in pixels between two child items vertically.
Returns | |
---|---|
int |
getVerticalSpacing
int getVerticalSpacing ()
Returns the vertical spacing in pixels between two child items.
Returns | |
---|---|
int |
The vertical spacing in pixels between two child items. |
getViewSelectedOffsets
void getViewSelectedOffsets (View view, int[] offsets)
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 |
int : offsets[0] holds offset of X, offsets[1] holds offset of Y.
|
getWindowAlignment
int getWindowAlignment ()
Returns the method for focused item alignment in the view.
Returns | |
---|---|
int |
WINDOW_ALIGN_BOTH_EDGE , WINDOW_ALIGN_LOW_EDGE ,
WINDOW_ALIGN_HIGH_EDGE or WINDOW_ALIGN_NO_EDGE .
|
getWindowAlignmentOffset
int getWindowAlignmentOffset ()
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 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
float getWindowAlignmentOffsetPercent ()
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 WINDOW_ALIGN_OFFSET_PERCENT_DISABLED if
disabled. Default value is 50.
|
hasOverlappingRendering
boolean hasOverlappingRendering ()
Returns | |
---|---|
boolean |
hasPreviousViewInSameRow
boolean hasPreviousViewInSameRow (int position)
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
boolean isChildLayoutAnimated ()
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
boolean isFocusDrawingOrderEnabled ()
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
boolean isFocusSearchDisabled ()
Returns true if focus search is disabled.
Returns | |
---|---|
boolean |
True if focus search is disabled. |
isItemAlignmentOffsetWithPadding
boolean isItemAlignmentOffsetWithPadding ()
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
Returns | |
---|---|
boolean |
isScrollEnabled
boolean isScrollEnabled ()
Returns true if scrolling is enabled, false otherwise.
Returns | |
---|---|
boolean |
True if scrolling is enabled, false otherwise. |
isWindowAlignmentPreferKeyLineOverHighEdge
boolean isWindowAlignmentPreferKeyLineOverHighEdge ()
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
boolean isWindowAlignmentPreferKeyLineOverLowEdge ()
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
boolean onRequestFocusInDescendants (int direction, Rect previouslyFocusedRect)
Parameters | |
---|---|
direction |
int |
previouslyFocusedRect |
Rect |
Returns | |
---|---|
boolean |
onRtlPropertiesChanged
void onRtlPropertiesChanged (int layoutDirection)
Notify layout manager that layout directionality has been updated
Parameters | |
---|---|
layoutDirection |
int |
removeOnChildViewHolderSelectedListener
void removeOnChildViewHolderSelectedListener (OnChildViewHolderSelectedListener listener)
Remove the callback invoked when an item in BaseGridView has been selected.
Parameters | |
---|---|
listener |
OnChildViewHolderSelectedListener : The listener to be removed.
|
scrollToPosition
void scrollToPosition (int position)
Convenience method to scroll to a certain position.
RecyclerView does not implement scrolling logic, rather forwards the call to
scrollToPosition(int)
Parameters | |
---|---|
position |
int : Scroll to this adapter position |
setAnimateChildLayout
void setAnimateChildLayout (boolean animateChildLayout)
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
void setChildrenVisibility (int visibility)
Changes and overrides children's visibility.
Parameters | |
---|---|
visibility |
int : See getVisibility() .
|
setFocusDrawingOrderEnabled
void setFocusDrawingOrderEnabled (boolean enabled)
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
void setFocusSearchDisabled (boolean disabled)
Disables or enables focus search.
Parameters | |
---|---|
disabled |
boolean : True to disable focus search, false to enable.
|
setGravity
void setGravity (int gravity)
Sets the gravity used for child view positioning. Defaults to GRAVITY_TOP|GRAVITY_START.
Parameters | |
---|---|
gravity |
int : See Gravity
|
setHasOverlappingRendering
void setHasOverlappingRendering (boolean hasOverlapping)
Parameters | |
---|---|
hasOverlapping |
boolean |
setHorizontalMargin
void setHorizontalMargin (int margin)
This method was deprecated
in API level 26.1.0.
Use setHorizontalSpacing(int)
Sets the spacing in pixels between two child items horizontally.
Parameters | |
---|---|
margin |
int |
setHorizontalSpacing
void setHorizontalSpacing (int spacing)
Sets the horizontal spacing in pixels between two child items.
Parameters | |
---|---|
spacing |
int : Horizontal spacing in pixels between two child items.
|
setInitialPrefetchItemCount
void setInitialPrefetchItemCount (int itemCount)
Sets the number of items to prefetch in
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
void setItemAlignmentOffset (int offset)
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
void setItemAlignmentOffsetPercent (float offsetPercent)
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
ITEM_ALIGN_OFFSET_PERCENT_DISABLED to disable.
|
setItemAlignmentOffsetWithPadding
void setItemAlignmentOffsetWithPadding (boolean withPadding)
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
Parameters | |
---|---|
withPadding |
boolean |
setItemAlignmentViewId
void setItemAlignmentViewId (int viewId)
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
.
Parameters | |
---|---|
viewId |
int |
setItemMargin
void setItemMargin (int margin)
This method was deprecated
in API level 26.1.0.
use setItemSpacing(int)
Sets the spacing in pixels between two child items.
Parameters | |
---|---|
margin |
int |
setItemSpacing
void setItemSpacing (int spacing)
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
void setLayoutEnabled (boolean layoutEnabled)
Enables or disables layout. All children will be removed when layout is disabled.
Parameters | |
---|---|
layoutEnabled |
boolean : True to enable layout, false otherwise.
|
setOnChildLaidOutListener
void setOnChildLaidOutListener (OnChildLaidOutListener listener)
Registers a callback to be invoked when an item in BaseGridView has been laid out.
Parameters | |
---|---|
listener |
OnChildLaidOutListener : The listener to be invoked.
|
setOnChildSelectedListener
void setOnChildSelectedListener (OnChildSelectedListener listener)
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
void setOnChildViewHolderSelectedListener (OnChildViewHolderSelectedListener listener)
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(OnChildViewHolderSelectedListener)
.
Parameters | |
---|---|
listener |
OnChildViewHolderSelectedListener : The listener to be invoked.
|
setOnKeyInterceptListener
void setOnKeyInterceptListener (BaseGridView.OnKeyInterceptListener listener)
Sets the key intercept listener.
Parameters | |
---|---|
listener |
BaseGridView.OnKeyInterceptListener : The key intercept listener.
|
setOnMotionInterceptListener
void setOnMotionInterceptListener (BaseGridView.OnMotionInterceptListener listener)
Sets the generic motion intercept listener.
Parameters | |
---|---|
listener |
BaseGridView.OnMotionInterceptListener : The motion intercept listener.
|
setOnTouchInterceptListener
void setOnTouchInterceptListener (BaseGridView.OnTouchInterceptListener listener)
Sets the touch intercept listener.
Parameters | |
---|---|
listener |
BaseGridView.OnTouchInterceptListener : The touch intercept listener.
|
setOnUnhandledKeyListener
void setOnUnhandledKeyListener (BaseGridView.OnUnhandledKeyListener listener)
Sets the unhandled key listener.
Parameters | |
---|---|
listener |
BaseGridView.OnUnhandledKeyListener : The unhandled key intercept listener.
|
setPruneChild
void setPruneChild (boolean pruneChild)
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
void setRecyclerListener (RecyclerView.RecyclerListener listener)
Register a listener that will be notified whenever a child view is recycled.
This listener will be called when a LayoutManager or the RecyclerView decides that a child view is no longer needed. If an application associates expensive or heavyweight data with item views, this may be a good place to release or free those resources.
Parameters | |
---|---|
listener |
RecyclerView.RecyclerListener : Listener to register, or null to clear
|
setSaveChildrenLimitNumber
void setSaveChildrenLimitNumber (int limitNumber)
Sets the limit number when getSaveChildrenPolicy()
is SAVE_LIMITED_CHILD
.
Parameters | |
---|---|
limitNumber |
int |
setSaveChildrenPolicy
void setSaveChildrenPolicy (int savePolicy)
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
void setScrollEnabled (boolean scrollEnabled)
Enables or disables scrolling. Disable is useful during transition.
Parameters | |
---|---|
scrollEnabled |
boolean : True to enable scroll, false to disable.
|
setSelectedPosition
void setSelectedPosition (int position, ViewHolderTask task)
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.
|
setSelectedPosition
void setSelectedPosition (int position, int scrollExtra)
Changes the selected item immediately without animation, scrollExtra is
applied in primary scroll direction. The scrollExtra will be kept until
another setSelectedPosition(int)
or setSelectedPositionSmooth(int)
call.
Parameters | |
---|---|
position |
int |
scrollExtra |
int |
setSelectedPosition
void setSelectedPosition (int position)
Changes the selected item immediately without animation.
Parameters | |
---|---|
position |
int |
setSelectedPositionSmooth
void setSelectedPositionSmooth (int position)
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
void setSelectedPositionSmooth (int position, ViewHolderTask task)
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.
|
setVerticalMargin
void setVerticalMargin (int margin)
This method was deprecated
in API level 26.1.0.
Use setVerticalSpacing(int)
Sets the spacing in pixels between two child items vertically.
Parameters | |
---|---|
margin |
int |
setVerticalSpacing
void setVerticalSpacing (int spacing)
Sets the vertical spacing in pixels between two child items.
Parameters | |
---|---|
spacing |
int : Vertical spacing between two child items.
|
setWindowAlignment
void setWindowAlignment (int windowAlignment)
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
void setWindowAlignmentOffset (int offset)
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
void setWindowAlignmentOffsetPercent (float offsetPercent)
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
WINDOW_ALIGN_OFFSET_PERCENT_DISABLED to disable.
Default value is 50.
|
setWindowAlignmentPreferKeyLineOverHighEdge
void setWindowAlignmentPreferKeyLineOverHighEdge (boolean preferKeyLineOverHighEdge)
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
void setWindowAlignmentPreferKeyLineOverLowEdge (boolean preferKeyLineOverLowEdge)
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
void smoothScrollToPosition (int position)
Starts a smooth scroll to an adapter position.
To support smooth scrolling, you must override
smoothScrollToPosition(RecyclerView, State, int)
and create a
RecyclerView.SmoothScroller
.
RecyclerView.LayoutManager
is responsible for creating the actual scroll action. If you want to
provide a custom smooth scroll logic, override
smoothScrollToPosition(RecyclerView, State, int)
in your
LayoutManager.
Parameters | |
---|---|
position |
int : The adapter position to scroll to |
Protected methods
dispatchGenericFocusedEvent
boolean dispatchGenericFocusedEvent (MotionEvent event)
Parameters | |
---|---|
event |
MotionEvent |
Returns | |
---|---|
boolean |
onFocusChanged
void onFocusChanged (boolean gainFocus, int direction, Rect previouslyFocusedRect)
Parameters | |
---|---|
gainFocus |
boolean |
direction |
int |
previouslyFocusedRect |
Rect |
Interfaces
- BaseGridView.OnKeyInterceptListener
- BaseGridView.OnMotionInterceptListener
- BaseGridView.OnTouchInterceptListener
- BaseGridView.OnUnhandledKeyListener
- BaseOnItemViewClickedListener
- BaseOnItemViewSelectedListener
- BrowseFrameLayout.OnChildFocusListener
- BrowseFrameLayout.OnFocusSearchListener
- FacetProvider
- FacetProviderAdapter
- FocusHighlight
- FragmentAnimationProvider
- ImeKeyMonitor
- ImeKeyMonitor.ImeKeyListener
- MultiActionsProvider
- OnActionClickedListener
- OnChildLaidOutListener
- OnChildSelectedListener
- OnItemViewClickedListener
- OnItemViewSelectedListener
- PlaybackSeekUi
- SearchBar.SearchBarListener
- SearchBar.SearchBarPermissionListener
- SearchEditText.OnKeyboardDismissListener
- SpeechRecognitionCallback
- TitleViewAdapter.Provider
- ViewHolderTask
Classes
- AbstractDetailsDescriptionPresenter
- AbstractDetailsDescriptionPresenter.ViewHolder
- AbstractMediaItemPresenter
- AbstractMediaItemPresenter.ViewHolder
- AbstractMediaListHeaderPresenter
- AbstractMediaListHeaderPresenter.ViewHolder
- Action
- ArrayObjectAdapter
- BaseCardView
- BaseCardView.LayoutParams
- BaseGridView
- BrowseFrameLayout
- ClassPresenterSelector
- ControlButtonPresenterSelector
- CursorObjectAdapter
- DetailsOverviewLogoPresenter
- DetailsOverviewLogoPresenter.ViewHolder
- DetailsOverviewRow
- DetailsOverviewRow.Listener
- DetailsOverviewRowPresenter
- DetailsOverviewRowPresenter.ViewHolder
- DetailsParallax
- DiffCallback
- DividerPresenter
- DividerRow
- FocusHighlightHelper
- FullWidthDetailsOverviewRowPresenter
- FullWidthDetailsOverviewRowPresenter.Listener
- FullWidthDetailsOverviewRowPresenter.ViewHolder
- FullWidthDetailsOverviewRowPresenter.ViewHolder.DetailsOverviewRowListener
- FullWidthDetailsOverviewSharedElementHelper
- GuidanceStylist
- GuidanceStylist.Guidance
- GuidedAction
- GuidedAction.Builder
- GuidedAction.BuilderBase
- GuidedActionDiffCallback
- GuidedActionEditText
- GuidedActionsStylist
- GuidedActionsStylist.ViewHolder
- GuidedDatePickerAction
- GuidedDatePickerAction.Builder
- GuidedDatePickerAction.BuilderBase
- HeaderItem
- HorizontalGridView
- HorizontalHoverCardSwitcher
- ImageCardView
- ItemAlignmentFacet
- ItemAlignmentFacet.ItemAlignmentDef
- ItemBridgeAdapter
- ItemBridgeAdapter.AdapterListener
- ItemBridgeAdapter.ViewHolder
- ItemBridgeAdapter.Wrapper
- ItemBridgeAdapterShadowOverlayWrapper
- ListRow
- ListRowHoverCardView
- ListRowPresenter
- ListRowPresenter.SelectItemViewHolderTask
- ListRowPresenter.ViewHolder
- ListRowView
- MultiActionsProvider.MultiAction
- ObjectAdapter
- ObjectAdapter.DataObserver
- OnChildViewHolderSelectedListener
- PageRow
- Parallax
- Parallax.FloatProperty
- Parallax.IntProperty
- Parallax.PropertyMarkerValue
- ParallaxEffect
- ParallaxTarget
- ParallaxTarget.DirectPropertyTarget
- ParallaxTarget.PropertyValuesHolderTarget
- PlaybackControlsRow
- PlaybackControlsRow.ClosedCaptioningAction
- PlaybackControlsRow.FastForwardAction
- PlaybackControlsRow.HighQualityAction
- PlaybackControlsRow.MoreActions
- PlaybackControlsRow.MultiAction
- PlaybackControlsRow.OnPlaybackProgressCallback
- PlaybackControlsRow.PictureInPictureAction
- PlaybackControlsRow.PlayPauseAction
- PlaybackControlsRow.RepeatAction
- PlaybackControlsRow.RewindAction
- PlaybackControlsRow.ShuffleAction
- PlaybackControlsRow.SkipNextAction
- PlaybackControlsRow.SkipPreviousAction
- PlaybackControlsRow.ThumbsAction
- PlaybackControlsRow.ThumbsDownAction
- PlaybackControlsRow.ThumbsUpAction
- PlaybackControlsRowPresenter
- PlaybackControlsRowPresenter.ViewHolder
- PlaybackRowPresenter
- PlaybackRowPresenter.ViewHolder
- PlaybackSeekDataProvider
- PlaybackSeekDataProvider.ResultCallback
- PlaybackSeekUi.Client
- PlaybackTransportRowPresenter
- PlaybackTransportRowPresenter.ViewHolder
- Presenter
- Presenter.ViewHolder
- Presenter.ViewHolderTask
- PresenterSelector
- PresenterSwitcher
- RecyclerViewParallax
- RecyclerViewParallax.ChildPositionProperty
- Row
- RowHeaderPresenter
- RowHeaderPresenter.ViewHolder
- RowHeaderView
- RowPresenter
- RowPresenter.ViewHolder
- SearchBar
- SearchEditText
- SearchOrbView
- SearchOrbView.Colors
- SectionRow
- ShadowOverlayContainer
- ShadowOverlayHelper
- ShadowOverlayHelper.Builder
- ShadowOverlayHelper.Options
- SinglePresenterSelector
- SparseArrayObjectAdapter
- SpeechOrbView
- TitleHelper
- TitleView
- TitleViewAdapter
- VerticalGridPresenter
- VerticalGridPresenter.ViewHolder
- VerticalGridView
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-04-11 UTC.