GridView and GridLayout in android

Harry Mad picture Harry Mad · Jun 12, 2014 · Viewed 9.7k times · Source

I trying to add child views for GridView in xml file but it is giving error and it working fine with GridLayout. so I want know .. What is difference b/w GridView and GridLayout in android ?

Answer

Wasim Ahmed picture Wasim Ahmed · Jun 12, 2014

The basic difference is that GridView is a scrollable View like ListView, and GridLayout is a layout. Both look the same but GridView is scrollable

According to the documentation for GridView, the formal definition is the following:

GridView

GridView is a ViewGroup that displays items in a two-dimensional, scrollable grid. The grid items are automatically inserted to the layout using a ListAdapter.

And the definition for GridLayout, from the same docs

GridLayout

A layout that places its children in a rectangular grid.

The grid is composed of a set of infinitely thin lines that separate the viewing area into cells. Throughout the API, grid lines are referenced by grid indices. A grid with N columns has N + 1 grid indices that run from 0 through N inclusive. Regardless of how GridLayout is configured, grid index 0 is fixed to the leading edge of the container and grid index N is fixed to its trailing edge (after padding is taken into account).