Added in API level 1

GridView


open class GridView : AbsListView
kotlin.Any
   ↳ 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
static Int

Creates as many columns as can fit on screen.

static Int

Disables stretching.

static Int

Stretches columns.

static Int

Stretches the spacing between columns.

static Int

Stretches the spacing between columns.

Inherited constants
Public constructors
GridView(context: Context!)

GridView(context: Context!, attrs: AttributeSet!)

GridView(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

GridView(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)

Public methods
open CharSequence!

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

open ListAdapter!

Returns the adapter currently associated with this widget.

open Int

Return the width of a column in the grid.

open Int

Describes how the child views are horizontally aligned.

open Int

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

open Int

Get the number of columns in the grid.

open Int

Return the requested width of a column in the grid.

open Int

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

open Int

open Int

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

open Unit

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

open Boolean
onKeyDown(keyCode: Int, event: KeyEvent!)

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.

open Boolean
onKeyMultiple(keyCode: Int, repeatCount: Int, event: KeyEvent!)

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

open Boolean
onKeyUp(keyCode: Int, event: KeyEvent!)

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.

open Unit

Sets the data behind this GridView.

open Unit
setColumnWidth(columnWidth: Int)

Set the width of columns in the grid.

open Unit
setGravity(gravity: Int)

Set the gravity for this grid.

open Unit
setHorizontalSpacing(horizontalSpacing: Int)

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

open Unit
setNumColumns(numColumns: Int)

Set the number of columns in the grid

open Unit

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

open Unit
setSelection(position: Int)

Sets the currently selected item

open Unit
setStretchMode(stretchMode: Int)

Control how items are stretched to fill their space.

open Unit
setVerticalSpacing(verticalSpacing: Int)

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

open Unit

Smoothly scroll to the specified adapter position offset.

open Unit

Smoothly scroll to the specified adapter position.

Protected methods
open Unit
attachLayoutAnimationParameters(child: View!, params: ViewGroup.LayoutParams!, index: Int, count: Int)

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

open Int

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

open Int

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

open Int

Compute the vertical range that the vertical scrollbar represents.

open Unit

Subclasses must override this method to layout their children.

open Unit
onFocusChanged(gainFocus: Boolean, direction: Int, previouslyFocusedRect: Rect?)

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

open Unit
onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int)

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

Inherited functions