Laying out data with TableLayout
Now, we will build a layout that resembles a spreadsheet. It will have neatly aligned cells with titles and data. In a real-world app, you would most likely use real live data from the user. As we are just practicing with different layouts, we will not go to this extent.
Follow these steps:
- In the project window, expand the
res
folder. Now, right-click thelayout
folder and select New. Notice that there is an option for Layout resource file. - Select Layout resource file, and you will see the New Resource File dialog window.
- In the File name: field, enter
my_table_layout
. This is the same name we used in the call tosetContentView
within theloadTableLayout
method. - Notice in the Root element: field that it has selected by default …ConstraintLayout as the option. Delete …
ConstraintLayout
and typeTableLayout
. - Click the OK button, and Android Studio will generate a new
TableLayou
t in an XML file calledmy_table_layout...