GridView


public class GridView
extends AbsListView

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.AdapterView<android.widget.ListAdapter>
         ↳ android.widget.AbsListView
           ↳ android.widget.GridView


A view that shows items in two-dimensional scrolling grid. The items in the grid come from the ListAdapter associated with this view.

See the Grid View guide.

Summary

XML attributes

android:columnWidth Specifies the fixed width for each column. 
android:gravity Specifies the gravity within each cell. 
android:horizontalSpacing Defines the default horizontal spacing between columns. 
android:numColumns Defines how many columns to show. 
android:stretchMode Defines how columns should stretch to fill the available empty space, if any. 
android:verticalSpacing Defines the default vertical spacing between rows. 

Inherited XML attributes

Constants

int AUTO_FIT

Creates as many columns as can fit on screen.

int NO_STRETCH

Disables stretching.

int STRETCH_COLUMN_WIDTH

Stretches columns.

int STRETCH_SPACING

Stretches the spacing between columns.

int STRETCH_SPACING_UNIFORM

Stretches the spacing between columns.

Inherited constants

Inherited fields

Public constructors

GridView(Context context)
GridView(Context context, AttributeSet attrs)
GridView(Context context, AttributeSet attrs, int defStyleAttr)
GridView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Public methods

CharSequence getAccessibilityClassName()

A TYPE_VIEW_SCROLLED event should be sent whenever a scroll happens, even if the mFirstPosition and the child count have not changed.

ListAdapter getAdapter()

Returns the adapter currently associated with this widget.

int getColumnWidth()

Return the width of a column in the grid.

int getGravity()

Describes how the child views are horizontally aligned.

int getHorizontalSpacing()

Returns the amount of horizontal spacing currently used between each item in the grid.

int getNumColumns()

Get the number of columns in the grid.

int getRequestedColumnWidth()

Return the requested width of a column in the grid.

int getRequestedHorizontalSpacing()

Returns the requested amount of horizontal spacing between each item in the grid.

int getStretchMode()
int getVerticalSpacing()

Returns the amount of vertical spacing between each item in the grid.

void onInitializeAccessibilityNodeInfoForItem(View view, int position, AccessibilityNodeInfo info)

Initializes an AccessibilityNodeInfo with information about a particular item in the list.

boolean onKeyDown(int keyCode, KeyEvent event)

Default implementation of KeyEvent.Callback.onKeyDown(): perform press of the view when KeyEvent.KEYCODE_DPAD_CENTER or KeyEvent.KEYCODE_ENTER is released, if the view is enabled and clickable.

boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event)

Default implementation of KeyEvent.Callback.onKeyMultiple(): always returns false (doesn't handle the event).

boolean onKeyUp(int keyCode, KeyEvent event)

Default implementation of KeyEvent.Callback.onKeyUp(): perform clicking of the view when KeyEvent.KEYCODE_DPAD_CENTER, KeyEvent.KEYCODE_ENTER or KeyEvent.KEYCODE_SPACE is released.

void setAdapter(ListAdapter adapter)

Sets the data behind this GridView.

void setColumnWidth(int columnWidth)

Set the width of columns in the grid.

void setGravity(int gravity)

Set the gravity for this grid.

void setHorizontalSpacing(int horizontalSpacing)

Set the amount of horizontal (x) spacing to place between each item in the grid.

void setNumColumns(int numColumns)

Set the number of columns in the grid

void setRemoteViewsAdapter(Intent intent)

Sets up this AbsListView to use a remote views adapter which connects to a RemoteViewsService through the specified intent.

void setSelection(int position)

Sets the currently selected item

void setStretchMode(int stretchMode)

Control how items are stretched to fill their space.

void setVerticalSpacing(int verticalSpacing)

Set the amount of vertical (y) spacing to place between each item in the grid.

void smoothScrollByOffset(int offset)

Smoothly scroll to the specified adapter position offset.

void smoothScrollToPosition(int position)

Smoothly scroll to the specified adapter position.

Protected methods

void attachLayoutAnimationParameters(View child, ViewGroup.LayoutParams params, int index, int count)

Subclasses should override this method to set layout animation parameters on the supplied child.

int computeVerticalScrollExtent()

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

int computeVerticalScrollOffset()

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

int computeVerticalScrollRange()

Compute the vertical range that the vertical scrollbar represents.

void layoutChildren()

Subclasses must override this method to layout their children.

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

Called by the view system when the focus state of this view changes.

void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

Measure the view and its content to determine the measured width and the measured height.

Inherited methods