English | Site Directory

Android - An Open Handset Alliance Project

android.widget
public class

android.widget.GridView

java.lang.Object
android.view.View Drawable.Callback KeyEvent.Callback
android.view.ViewGroup ViewManager ViewParent
android.widget.AdapterView
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.

Also see ViewGroup.LayoutParams for layout attributes.

Summary

XML Attributes

Attribute name Related methods  
android:columnWidth setColumnWidth(int)
 
 
android:gravity setGravity(int)
 
Specifies how to place an object, both its x and y axis, within a larger containing object. 
android:horizontalSpacing setHorizontalSpacing(int)
 
 
android:numColumns setNumColumns(int)
 
 
android:stretchMode setStretchMode(int)
 
 
android:verticalSpacing setVerticalSpacing(int)
 
 
XML Attributes inherited from class android.widget.AbsListView
XML Attributes inherited from class android.view.ViewGroup
XML Attributes inherited from class android.view.View

Constants

      Value  
int  AUTO_FIT    -1  0xffffffff 
int  NO_STRETCH    0x00000000 
int  STRETCH_COLUMN_WIDTH    0x00000002 
int  STRETCH_SPACING    0x00000001 
Constants inherited from class android.widget.AbsListView
Constants inherited from class android.widget.AdapterView
Constants inherited from class android.view.ViewGroup
Constants inherited from class android.view.View
Fields inherited from class android.widget.AbsListView
Fields inherited from class android.widget.AdapterView
Fields inherited from class android.view.ViewGroup
Fields inherited from class android.view.View

Public Constructors

          GridView(Context context)
          GridView(Context context, AttributeSet attrs, Map inflateParams)
          GridView(Context context, AttributeSet attrs, Map inflateParams, int defStyle)

Public Methods

        ListAdapter  getAdapter()
        int  getStretchMode()
        boolean  onKeyDown(int keyCode, KeyEvent event)
Default implementation of KeyEvent.Callback.onKeyMultiple(): perform press of the view when KEYCODE_DPAD_CENTER or KEYCODE_NEWLINE is released, if the view is enabled and clickable.
        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  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.

Protected Methods

        boolean  arrowScroll(int direction)
Scrolls to the next or previous item, horizontally or vertically.
        void  attachLayoutAnimationParameters(View child, LayoutParams params, int index, int count)
Subclasses should override this method to set layout animation parameters on the supplied child.
        int  findMotionRow(int y)
Find the row closest to y.
        boolean  fullScroll(int direction)
Go to the last or first item if possible.
        void  layoutChildren()
        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.

        boolean  pageScroll(int direction)
Scrolls up or down by the number of items currently present on screen.
        void  setSelectionInt(int position)
Makes the item at the supplied position selected.
Methods inherited from class android.widget.AbsListView