Ice Cream Sandwich GridLayout

Android 4.0 (Ice Cream Sandwich) introduced a new type of layouts: the Gridlayout.
Gridlayout is like the <Table> tag in HTML. child widgets are arranged in Cells made of Rows and Columns.

Grid layout is a ViewGroup that can be used in constructing dashboard activities like that one in the Google Plus application:

so let's see what we can do with the GridLayout:
we'll construct a simple dashboard layout like this:
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:rowCount="5"
    android:columnCount="3"
    >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button 1"
        android:layout_row="0"
        android:layout_column="0"
        android:layout_marginLeft="5dp"
         />
    
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button 2"
        android:layout_row="0"
        android:layout_column="1"
        android:layout_margin="5dp" />
    
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button 3"
        android:layout_row="1"
        android:layout_column="0"
        android:layout_margin="5dp" />
    
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button 4"
        android:layout_row="1"
        android:layout_column="1"
        android:layout_margin="5dp" />
    
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button 5"
        android:layout_row="2"
        android:layout_column="0"
        android:layout_margin="5dp" />
    
    

</GridLayout>


Widgets are placed in position specified by android:layout_column and android:layout_row properties.
we can organize the widgets in a similar way by using the new Space View like this:
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:rowCount="5"
android:columnCount="3"

>

<Space
android:layout_width="5dp"
android:layout_height="5dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1"
android:layout_row="0"
android:layout_column="0"
/>
<Space
android:layout_width="5dp"
android:layout_height="5dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2"
android:layout_row="0"
android:layout_column="1"
/>
<Space
android:layout_width="5dp"
android:layout_height="5dp"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 3"
android:layout_row="1"
android:layout_column="0"
/>
<Space
android:layout_width="5dp"
android:layout_height="5dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 4"
android:layout_row="1"
android:layout_column="1"
/>
<Space
android:layout_width="5dp"
android:layout_height="5dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 5"
android:layout_row="2"
android:layout_column="0"
/>
<Space
android:layout_width="5dp"
android:layout_height="5dp"/>


</GridLayout>

Reactions: 

Contest: Do you think Android Ice Cream Sandwich will beat Apple iOS 5

Hello everybody.
Google will release the next major Android update: Android 4.0 (Ice cream Sandwich) along with it's next flagship phone: the Nexus Prime.

Join our Contest and have the chance to win a copy of one of these wonderful Android books:

  1. Android, A Complete Course, From Basics To Enterprise Edition.
  2. Android, A Quick Course.
  3. Android, An Enterprise Edition Vision.




all you've got to do is to drop a comment answering the following question:
Do you think Android Ice Cream Sandwich will beat Apple iOS 5 ?

the contest ends on November 7th, winners will be announced then.
waiting for your comments


Reactions: