Monday, November 28, 2011

New Layout Widgets: Space and GridLayout

I've posted an article, New Layout Widgets: Space and GridLayout, on the Android Developer's blog. The article gives an overview of the new layout widgets we've added to the Android platform for the latest release: Ice Cream Sandwich. 


  1. Hi Philip,

    we met at Devoxx, where I gave the intro workshop. I'm trying to use GridLayout to define a 2x2 table with horizontally equally sized boxes where the Gridlayout takes the full horizontal space.

    Is that possible, seems like the settings do not allow that.

  2. Hi Lars!

    Yes - I remember your most excellent talk. To answer your question - I'm afraid not. GridLayout does not support the principle of weight and there's no other way to distribute excess space evenly between multiple components. For now, the best solution is to embed a LinearLayout in the appropriate cells of your grid and use LinearLayout's weight feature to distribute the space amongst the appropriate components.


  3. Thanks Philip for the answer. I tried that but the boxes refuses to get the same size, either they stay as large as there children or one of them occupies the whole space.

    Would it be possible for you to post an example xml layout file which does this?

  4. Just so you are aware, the images in this article are no longer working. As a beginner programmer looking for a good example of the GridLayout I was disappointed to find your article missing the pictures....luckily I was still able to benefit from the code example in the article.