Saturday, November 19, 2011

Using the new GridLayout on pre Ice Cream Sandwich devices

To address several drawbacks of nested layouts on the Android platform, two new widgets were introduced with the release of Ice Cream Sandwich (ICS): Space and GridLayout. Detailed info about these two new widgets can be found in a blog post by Philip Milne on the Android Developers blog and in the API docs.

Dianne Hackborn of the Android framework team mentioned in a post that they hope to have a version of this GridLayout available in the Support Package so that you can statically link this into your applications for use on previous versions of Android.

Now, with the drop of the ICS sources, all the source code related to these two new widgets came immediately available. After a first look on the sources it turned out that there is not much ICS-specific code. So I created a sample project that includes the related sources from ICS and the two GridLayout samples from the Api Demos application. Both UIs of the screenshots below are created through an XML-instantiated GridLayout. The left one is running on an emulator running Cupcake (1.5). And the right one is running on an emulator running Ice Cream Sandwich (4.0).


So, at this is moment it is already possible to start porting your UIs to a GridLayout. The main difference with the ICS specification and implementation is that you need to:
  • use a different XML namespace to use as prefix when specifying the attributes (columnCount, layout_columnSpan, layout_column, ...) related to the GridLayout
  • specify the full class name of the widgets GridLayout and Space in your layouts
An example of the ported XML layout from the Api Demos can be found here.

No comments:

Post a Comment