Align Buttons in GridLayout

aviran picture aviran · Sep 26, 2012 · Viewed 14.1k times · Source

My layout code and its graphical representation is:

enter image description here

This is just an example, I have about 30 Buttons in my application inside a GridLayout. I want my Buttons to fill their entire cell in the grid and the grid's columns should be in even width/height.

I cant seem to get it done, any help would be welcome.

Answer

user picture user · Sep 26, 2012

I haven't use GridLayout to much to recommend something about using it, what I can recommend you is to use a TableLayout. I say this because your layout fits in the TableLayout's scope pretty well and after a quick browsing of GridLayout's documentation this seems like a problem:

GridLayout does not provide support for the principle of weight, as defined in weight. In general, it is not therefore possible to configure a GridLayout to distribute excess space between multiple components.

Also GridLayout was introduced in ICS.

You can see an example for your layout using TableLayout here:

https://gist.github.com/3788301

If you don't want the table to fill the entire height then remove the weigthSum property from the TableLayout and layout_weight="1" from the TableRows.