Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GridLayout vs TableLayout

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?

like image 398
meds Avatar asked Apr 30 '13 13:04

meds


People also ask

Is GridLayout deprecated?

GridView and ConstraintLayout are not equivalent things, so that recommendation does not make sense. GridLayout is comparable to ConstraintLayout . GridLayout is also not deprecated.

What is the difference between GridLayout and GridView?

Let us not get confused with GridView and GridLayout to be the same. GridView simply gives us a two-dimensional view to display the items on the screen, under ViewGroup. On the other hand, GridLayout is a layout manager that arranges the views in a grid.

How do Gridlayouts differ from Tablelayouts?

With the TableLayout , rows and columns are added dynamically as you build the table. With the GridLayout , row and column sizes are defined in the layout definition. Neither layout is better, it's just a matter of using the best layout for your needs.

What is GridLayout spec?

android.widget.GridLayout.Spec. A Spec defines the horizontal or vertical characteristics of a group of cells. Each spec. defines the grid indices and alignment along the appropriate axis. The grid indices are the leading and trailing edges of this cell group.


1 Answers

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.

like image 195
TronicZomB Avatar answered Oct 18 '22 02:10

TronicZomB