GridLayout vs TableLayout

meds picture meds · Apr 30, 2013 · Viewed 14.3k times · Source

I'm unsure as to what the differences between the two of them are and which I should use for my purpouses?

What I'm trying to do is create a custom virtual numpad with text inputs and that can dynamically change its contents to have a date picker.

So I need a layout system which supports many different sized cells inside it.

Which better suits my needs and what's the difference?

Answer

TronicZomB picture TronicZomB · Apr 30, 2013

In my experience I had both GridLayout and TableLayout give me the same results. They both seem to stretch the columns to fit the widest child element. Neither will give you gird lines or borders around the cells.

From the official docs on GridLayout:

Row and Column Specs Children occupy one or more contiguous cells, as defined by their rowSpec and columnSpec layout parameters. Each spec defines the set of rows or columns that are to be occupied; and how children should be aligned within the resulting group of cells. Although cells do not normally overlap in a GridLayout, GridLayout does not prevent children being defined to occupy the same cell or group of cells. In this case however, there is no guarantee that children will not themselves overlap after the layout operation completes.

and from the TableLayout:

The table has as many columns as the row with the most cells. A table can leave cells empty. Cells can span columns, as they can in HTML.

So it seems to me that the GridLayout is a bit more versatile and probably what you are looking for.