Android APIs
public class

VerticalGridView

extends RecyclerView
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.support.v7.widget.RecyclerView
         ↳ android.support.v17.leanback.widget.VerticalGridView

Class Overview

A ViewGroup that shows items in a vertically scrolling list. The items come from the RecyclerView.Adapter associated with this view.

RecyclerView.Adapter can optionally implement FacetProviderAdapter which provides FacetProvider for a given view type; RecyclerView.ViewHolder can also implement FacetProvider. Facet from ViewHolder has a higher priority than the one from FacetProiderAdapter associated with viewType. Supported optional facets are:

  1. ItemAlignmentFacet When this facet is provided by ViewHolder or FacetProviderAdapter, it will override the item alignment settings set on VerticalGridView. This facet also allows multiple alignment positions within one ViewHolder.

Summary

[Expand]
Inherited XML Attributes
From class android.support.v7.widget.RecyclerView
From class android.view.ViewGroup
From class android.view.View
Constants
int FOCUS_SCROLL_ALIGNED Always keep focused item at a aligned position.
int FOCUS_SCROLL_ITEM Scroll to make the focused item inside client area.
int FOCUS_SCROLL_PAGE Scroll a page of items when focusing to item outside the client area.
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 getSaveChildrenLimitNumber().
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 middle location.
float WINDOW_ALIGN_OFFSET_PERCENT_DISABLED Value indicates that percent is not used.
[Expand]
Inherited Constants
From class android.support.v7.widget.RecyclerView
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
VerticalGridView(Context context)
VerticalGridView(Context context, AttributeSet attrs)
VerticalGridView(Context context, AttributeSet attrs, int defStyle)
Public Methods
boolean dispatchGenericFocusedEvent(MotionEvent event)
Dispatch a generic motion event to the currently focused view.
boolean dispatchKeyEvent(KeyEvent event)
Dispatch a key event to the next view on the focus path.
boolean dispatchTouchEvent(MotionEvent event)
Pass the touch screen motion event down to the target view, or this view if it is the target.
View focusSearch(int direction)
Find the nearest view in the specified direction that can take focus.
int getChildDrawingOrder(int childCount, int i)
Returns the index of the child to draw for this iteration.
int getFocusScrollStrategy()
Returns the strategy used to scroll in response to item focus changing.
int getHorizontalMargin()
Returns the margin in pixels between two child items horizontally.
int getItemAlignmentOffset()
Returns the absolute offset in pixels for item alignment.
float getItemAlignmentOffsetPercent()
Returns the offset percent for item alignment in addition to getItemAlignmentOffset().
int getItemAlignmentViewId()
Returns the id of the view to align with, or zero for the item view itself.
BaseGridView.OnUnhandledKeyListener getOnUnhandledKeyListener()
Returns the unhandled key listener.
final int getSaveChildrenLimitNumber()
Returns the limit used when when getSaveChildrenPolicy() is SAVE_LIMITED_CHILD
final int getSaveChildrenPolicy()
Returns the policy for saving children.
int getSelectedPosition()
Returns the selected item position.
int getSelectedSubPosition()
Returns the sub selected item position started from zero.
int getVerticalMargin()
Returns the margin in pixels between two child items vertically.
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.
float getWindowAlignmentOffsetPercent()
Returns the offset percent for window alignment in addition to getWindowAlignmentOffset().
boolean hasOverlappingRendering()
Returns whether this View has content which overlaps.
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 default "focus draw at last" order rule is enabled.
final boolean isFocusSearchDisabled()
Returns true if focus search is disabled.
boolean isItemAlignmentOffsetWithPadding()
Returns true if include padding in calculating item align offset.
boolean isScrollEnabled()
Returns true if scrolling is enabled.
boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect)
Look for a descendant to call requestFocus() on.
void onRtlPropertiesChanged(int layoutDirection)
Notify layout manager that layout directionality has been updated
void setAnimateChildLayout(boolean animateChildLayout)
Sets whether an animation 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 setColumnWidth(int width)
Sets the column width.
void setFocusDrawingOrderEnabled(boolean enabled)
Enables or disables the default "focus draw at last" order rule.
void setFocusScrollStrategy(int scrollStrategy)
Sets the strategy used to scroll in response to item focus changing:
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)
Sets the margin in pixels between two child items horizontally.
void setItemAlignmentOffset(int offset)
Sets the absolute offset in pixels for item alignment.
void setItemAlignmentOffsetPercent(float offsetPercent)
Sets the offset percent for item alignment in addition to getItemAlignmentOffset().
void setItemAlignmentOffsetWithPadding(boolean withPadding)
Set to true if include padding in calculating item align offset.
void setItemAlignmentViewId(int viewId)
Sets the id of the view to align with.
void setItemMargin(int margin)
Sets the margin in pixels between two child items.
void setLayoutEnabled(boolean layoutEnabled)
Enables or disables layout.
void setNumColumns(int numColumns)
Sets the number of columns.
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 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, 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 setSelectedPositionSmoothWithSub(int position, int subposition)
Changes the selected item and/or subposition, runs an animation to scroll to the target position.
void setSelectedPositionWithSub(int position, int subposition, int scrollExtra)
Changes the selected item and/or subposition immediately without animation, scrollExtra is applied in primary scroll direction.
void setSelectedPositionWithSub(int position, int subposition)
Changes the selected item and/or subposition immediately without animation.
void setVerticalMargin(int margin)
Sets the margin in pixels between two child items vertically.
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.
void setWindowAlignmentOffsetPercent(float offsetPercent)
Sets the offset percent for window alignment in addition to getWindowAlignmentOffset().
Protected Methods
void initAttributes(Context context, AttributeSet attrs)
void initBaseGridViewAttributes(Context context, AttributeSet attrs)
void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect)
Called by the view system when the focus state of this view changes.
[Expand]
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.NestedScrollingChild
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

Constants

public static final int FOCUS_SCROLL_ALIGNED

Always keep focused item at a aligned position. Developer can use WINDOW_ALIGN_XXX and ITEM_ALIGN_XXX to define how focused item is aligned. In this mode, the last focused position will be remembered and restored when focus is back to the view.

Constant Value: 0 (0x00000000)

public static final int FOCUS_SCROLL_ITEM

Scroll to make the focused item inside client area.

Constant Value: 1 (0x00000001)

public static final int FOCUS_SCROLL_PAGE

Scroll a page of items when focusing to item outside the client area. The page size matches the client area size of RecyclerView.

Constant Value: 2 (0x00000002)

public static final float ITEM_ALIGN_OFFSET_PERCENT_DISABLED

Value indicates that percent is not used.

Constant Value: -1.0

public static final 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)

public static final int SAVE_LIMITED_CHILD

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

Constant Value: 2 (0x00000002)

public static final int SAVE_NO_CHILD

Dont save states of any child views.

Constant Value: 0 (0x00000000)

public static final int SAVE_ON_SCREEN_CHILD

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

Constant Value: 1 (0x00000001)

public static final 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 middle location.

The middle 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)

public static final 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 maintains a middle location.

For HorizontalGridView, high edge refers to right edge when RTL is false or left edge when RTL is true. For VerticalGridView, high edge refers to bottom edge.

The middle 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: 2 (0x00000002)

public static final 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 maintains a middle location.

For HorizontalGridView, low edge refers to left edge when RTL is false or right edge when RTL is true. For VerticalGridView, low edge refers to top edge.

The middle 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: 1 (0x00000001)

public static final int WINDOW_ALIGN_NO_EDGE

The focused item always stays in a middle location.

The middle 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)

public static final float WINDOW_ALIGN_OFFSET_PERCENT_DISABLED

Value indicates that percent is not used.

Constant Value: -1.0

Public Constructors

public VerticalGridView (Context context)

public VerticalGridView (Context context, AttributeSet attrs)

public VerticalGridView (Context context, AttributeSet attrs, int defStyle)

Public Methods

public boolean dispatchGenericFocusedEvent (MotionEvent event)

Dispatch a generic motion event to the currently focused view.

Do not call this method directly. Call dispatchGenericMotionEvent(MotionEvent) instead.

Parameters
event The motion event to be dispatched.
Returns
  • True if the event was handled by the view, false otherwise.

public boolean dispatchKeyEvent (KeyEvent event)

Dispatch a key event to the next view on the focus path. This path runs from the top of the view tree down to the currently focused view. If this view has focus, it will dispatch to itself. Otherwise it will dispatch the next node down the focus path. This method also fires any key listeners.

Parameters
event The key event to be dispatched.
Returns
  • True if the event was handled, false otherwise.

public boolean dispatchTouchEvent (MotionEvent event)

Pass the touch screen motion event down to the target view, or this view if it is the target.

Parameters
event The motion event to be dispatched.
Returns
  • True if the event was handled by the view, false otherwise.

public View focusSearch (int direction)

Find the nearest view in the specified direction that can take focus. This does not actually give focus to that view.

Parameters
direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT
Returns
  • The nearest focusable in the specified direction, or null if none can be found.

public int getChildDrawingOrder (int childCount, int i)

Returns the index of the child to draw for this iteration. Override this if you want to change the drawing order of children. By default, it returns i.

NOTE: In order for this method to be called, you must enable child ordering first by calling setChildrenDrawingOrderEnabled(boolean).

Parameters
i The current iteration.
Returns
  • The index of the child to draw this iteration.

public int getFocusScrollStrategy ()

Returns the strategy used to scroll in response to item focus changing.

public int getHorizontalMargin ()

Returns the margin in pixels between two child items horizontally.

public int getItemAlignmentOffset ()

Returns the absolute offset in pixels for item alignment.

Returns
  • The number of pixels to offset. Will be negative for alignment from the high edge, or positive for alignment from the low edge. Default value is 0.

public float getItemAlignmentOffsetPercent ()

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

Returns

public int getItemAlignmentViewId ()

Returns the id of the view to align with, or zero for the item view itself.

public BaseGridView.OnUnhandledKeyListener getOnUnhandledKeyListener ()

Returns the unhandled key listener.

public final int getSaveChildrenLimitNumber ()

Returns the limit used when when getSaveChildrenPolicy() is SAVE_LIMITED_CHILD

public final int getSaveChildrenPolicy ()

Returns the policy for saving children.

public int getSelectedPosition ()

Returns the selected item position.

public int getSelectedSubPosition ()

Returns the sub selected item position started from zero. An item can have multiple ItemAlignmentFacets provided by RecyclerView.ViewHolder or FacetProviderAdapter. Zero is returned when no ItemAlignmentFacet is defined.

public int getVerticalMargin ()

Returns the margin in pixels between two child items vertically.

public void getViewSelectedOffsets (View view, int[] offsets)

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

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

public int getWindowAlignment ()

Returns the method for focused item alignment in the view.

public int getWindowAlignmentOffset ()

Returns the offset in pixels for window alignment.

Returns
  • 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.

public float getWindowAlignmentOffsetPercent ()

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

Returns

public boolean hasOverlappingRendering ()

Returns whether this View has content which overlaps.

This function, intended to be overridden by specific View types, is an optimization when alpha is set on a view. If rendering overlaps in a view with alpha < 1, that view is drawn to an offscreen buffer and then composited into place, which can be expensive. If the view has no overlapping rendering, the view can draw each primitive with the appropriate alpha value directly. An example of overlapping rendering is a TextView with a background image, such as a Button. An example of non-overlapping rendering is a TextView with no background, or an ImageView with only the foreground image. The default implementation returns true; subclasses should override if they have cases which can be optimized.

The current implementation of the saveLayer and saveLayerAlpha methods in Canvas necessitates that a View return true if it uses the methods internally without passing the CLIP_TO_LAYER_SAVE_FLAG.

Returns
  • true if the content in this view might overlap, false otherwise.

public 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. So application should check in both OnChildSelectedListener and OnChildLaidOutListener.

Parameters
position Position in adapter.

public boolean isChildLayoutAnimated ()

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

Unstable API, might change later.

public boolean isFocusDrawingOrderEnabled ()

Returns true if default "focus draw at last" order rule is enabled.

public final boolean isFocusSearchDisabled ()

Returns true if focus search is disabled.

public boolean isItemAlignmentOffsetWithPadding ()

Returns true if include padding in calculating item align offset.

public boolean isScrollEnabled ()

Returns true if scrolling is enabled.

public boolean onRequestFocusInDescendants (int direction, Rect previouslyFocusedRect)

Look for a descendant to call requestFocus() on. Called by requestFocus(int, android.graphics.Rect) when it wants to request focus within its children. Override this to customize how your ViewGroup requests focus within its children.

Parameters
direction One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT
previouslyFocusedRect The rectangle (in this View's coordinate system) to give a finer grained hint about where focus is coming from. May be null if there is no hint.
Returns
  • Whether focus was taken.

public void onRtlPropertiesChanged (int layoutDirection)

Notify layout manager that layout directionality has been updated

Parameters
layoutDirection the direction of the layout

public void setAnimateChildLayout (boolean animateChildLayout)

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

Unstable API, might change later.

public void setChildrenVisibility (int visibility)

Changes and overrides children's visibility.

public void setColumnWidth (int width)

Sets the column width.

Parameters
width May be WRAP_CONTENT, or a size in pixels. If zero, column width will be fixed based on number of columns and view width.

public void setFocusDrawingOrderEnabled (boolean enabled)

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

public void setFocusScrollStrategy (int scrollStrategy)

Sets the strategy used to scroll in response to item focus changing:

public final void setFocusSearchDisabled (boolean disabled)

Disables or enables focus search.

public void setGravity (int gravity)

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

Parameters
gravity See Gravity

public void setHasOverlappingRendering (boolean hasOverlapping)

public void setHorizontalMargin (int margin)

Sets the margin in pixels between two child items horizontally.

public void setItemAlignmentOffset (int offset)

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

Parameters
offset The number of pixels to offset. Can be negative for alignment from the high edge, or positive for alignment from the low edge.

public 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 Percentage to offset. E.g., 40 means 40% of the width from the low edge. Use ITEM_ALIGN_OFFSET_PERCENT_DISABLED to disable.

public void setItemAlignmentOffsetWithPadding (boolean withPadding)

Set to true if include padding in calculating item align offset. Item alignment settings are ignored for the child if ItemAlignmentFacet is provided by RecyclerView.ViewHolder or FacetProviderAdapter.

Parameters
withPadding When it is true: we include left/top padding for positive item offset, include right/bottom padding for negative item offset.

public void setItemAlignmentViewId (int viewId)

Sets the id of the view to align with. Use NO_ID (default) for the item view itself. Item alignment settings are ignored for the child if ItemAlignmentFacet is provided by RecyclerView.ViewHolder or FacetProviderAdapter.

public void setItemMargin (int margin)

Sets the margin in pixels between two child items.

public void setLayoutEnabled (boolean layoutEnabled)

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

public void setNumColumns (int numColumns)

Sets the number of columns. Defaults to one.

public void setOnChildLaidOutListener (OnChildLaidOutListener listener)

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

Parameters
listener The listener to be invoked.

public 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 The listener to be invoked.

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

Parameters
listener The listener to be invoked.

public void setOnKeyInterceptListener (BaseGridView.OnKeyInterceptListener listener)

Sets the key intercept listener.

public void setOnMotionInterceptListener (BaseGridView.OnMotionInterceptListener listener)

Sets the generic motion intercept listener.

public void setOnTouchInterceptListener (BaseGridView.OnTouchInterceptListener listener)

Sets the touch intercept listener.

public void setOnUnhandledKeyListener (BaseGridView.OnUnhandledKeyListener listener)

Sets the unhandled key listener.

public void setPruneChild (boolean pruneChild)

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

public 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 Listener to register, or null to clear

public final void setSaveChildrenLimitNumber (int limitNumber)

Sets the limit number when getSaveChildrenPolicy() is SAVE_LIMITED_CHILD.

public final void setSaveChildrenPolicy (int savePolicy)

Sets the policy for saving children.

public void setScrollEnabled (boolean scrollEnabled)

Enables or disables scrolling. Disable is useful during transition.

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

public void setSelectedPosition (int position)

Changes the selected item immediately without animation.

public void setSelectedPositionSmooth (int position)

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

public void setSelectedPositionSmoothWithSub (int position, int subposition)

Changes the selected item and/or subposition, runs an animation to scroll to the target position.

public void setSelectedPositionWithSub (int position, int subposition, int scrollExtra)

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

public void setSelectedPositionWithSub (int position, int subposition)

Changes the selected item and/or subposition immediately without animation.

public void setVerticalMargin (int margin)

Sets the margin in pixels between two child items vertically.

public void setWindowAlignment (int windowAlignment)

Sets the method for focused item alignment in the view.

public void setWindowAlignmentOffset (int offset)

Sets the offset in pixels for window alignment.

Parameters
offset 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.

public void setWindowAlignmentOffsetPercent (float offsetPercent)

Sets the offset percent for window alignment in addition to getWindowAlignmentOffset().

Parameters
offsetPercent 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.

Protected Methods

protected void initAttributes (Context context, AttributeSet attrs)

protected void initBaseGridViewAttributes (Context context, AttributeSet attrs)

protected void onFocusChanged (boolean gainFocus, int direction, Rect previouslyFocusedRect)

Called by the view system when the focus state of this view changes. When the focus change event is caused by directional navigation, direction and previouslyFocusedRect provide insight into where the focus is coming from. When overriding, be sure to call up through to the super class so that the standard focus handling will occur.

Parameters
gainFocus True if the View has focus; false otherwise.
direction The direction focus has moved when requestFocus() is called to give this view focus. Values are FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_FORWARD, or FOCUS_BACKWARD. It may not always apply, in which case use the default.
previouslyFocusedRect The rectangle, in this view's coordinate system, of the previously focused view. If applicable, this will be passed in as finer grained information about where the focus is coming from (in addition to direction). Will be null otherwise.