public class

GridView

extends AbsListView
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.AdapterView<T extends android.widget.Adapter>
         ↳ android.widget.AbsListView
           ↳ android.widget.GridView

Class Overview

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

Summary

XML Attributes
Attribute Name Related Method Description
android:columnWidth setColumnWidth(int) Specifies the fixed width for each column. 
android:gravity setGravity(int) Specifies the gravity within each cell. 
android:horizontalSpacing setHorizontalSpacing(int) Defines the default horizontal spacing between columns. 
android:numColumns setNumColumns(int) Defines how many columns to show. 
android:stretchMode setStretchMode(int) Defines how columns should stretch to fill the available empty space, if any. 
android:verticalSpacing setVerticalSpacing(int) Defines the default vertical spacing between rows. 
[Expand]
Inherited XML Attributes
From class android.widget.AbsListView
From class android.view.ViewGroup
From class android.view.View
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.
[Expand]
Inherited Constants
From class android.widget.AbsListView
From class android.widget.AdapterView
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
GridView(Context context)
GridView(Context context, AttributeSet attrs)
GridView(Context context, AttributeSet attrs, int defStyle)
Public Methods
ListAdapter getAdapter()
Returns the adapter currently associated with this widget.
int getNumColumns()
Get the number of columns in the grid.
int getStretchMode()
boolean onKeyDown(int keyCode, KeyEvent event)
Default implementation of KeyEvent.Callback.onKeyDown(): perform press of the view when KEYCODE_DPAD_CENTER or 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 KEYCODE_DPAD_CENTER or KEYCODE_ENTER 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)
Describes how the child views are horizontally aligned.
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 horizontal 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.

[Expand]
Inherited Methods
From class android.widget.AbsListView
From class android.widget.AdapterView
From class android.view.ViewGroup
From class android.view.View