Android 9 Development Cookbook(Third Edition)
上QQ阅读APP看书,第一时间看更新

How it works...

As you can see when viewing the tables created, the tables basically look the same on screen. The main difference is the code to create them.

In the TableLayout XML, each row is added to the table using TableRow. Each View becomes a column. This is not a requirement as cells can be skipped or left empty. (See how to specify the cell location in TableRow in the following section.)

GridLayout uses the opposite approach. The number of rows and columns are specified when creating the table. We don't have to specify the row or column information (though we can, as discussed later). Android will automatically add each View to the cells in order.