Pages
Ice Cream Sandwich GridLayout
11:14 PM
Posted by Mina Samy
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:
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:
<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: |
This entry was posted on October 4, 2009 at 12:14 pm, and is filed under
Android 4.0,
GridLayout,
Ice Cream Sandwich,
Space
. Follow any responses to this post through RSS. You can leave a response, or trackback from your own site.
Subscribe to:
Post Comments (Atom)












October 28, 2011 11:24 AM
How do you make a cell fill the entire cell. Like create a 3*3 grid with all cells taking the same space.
December 3, 2011 10:27 AM
Great tutorial....I will surely use it for my apps...thank you.
December 19, 2011 1:26 PM
This is really good information I have visited this blog to read something fresh and I really admire you efforts in doing so.
January 4, 2012 10:01 AM
yes
android is the future of busines and android app developers are being famouse in the world.
in this blog if you provide some more information about android app developers so it will be great.
February 21, 2012 9:31 AM
I like your blog advantages.I learn some good tips about iPhone developer by read this post.This is one of the important post.supper.