Android TableLayout is a ViewGroup subclass which is used to display the child View elements in rows and columns. It will arrange all the children elements into rows and columns and does not display any border lines in between rows, columns or cells.
The working of TableLayout is almost similar to HTML table and it contains as many columns as row with the most cells.
How to declare TableLayout and TableRow?
The TableLayout can be defined using <TableLayout> like below:
and TableRow can be defined using
In this file, we declare the TableLayout and start adding table rows with the help of TableRow. We are creating ranking table of players where we define four columns Rank, Name, Country and Points.
The code for the Table is:
When we have created layout, we need to load the XML layout resource from our activity onCreate() callback method and access the UI element form the XML using findViewById.
We need to run using Android Virtual Device(AVD) to see the output.
- Android Slide Up/Down in Kotlin
- Android Animations in Kotlin
- Android ListView in Kotlin
- Android Toast in Kotlin
- Android FrameLayout in Kotlin
- Android Fade In/Out in Kotlin
- Android RelativeLayout in Kotlin
- Android LinearLayout in Kotlin
- Android EditText in Kotlin
- Kotlin Android Tutorial
- Android progress notifications in Kotlin
- Thread Priority in Kotlin & Android
- How to create project in Android Studio using Kotlin
- Difference between Java and Kotlin in Android with Examples
- Why You Should Switch to Kotlin from Java to Develop Android Apps?
- Kotlin | apply vs with
- Kotlin Set : setOf()
- Kotlin Ranges
- Kotlin String
- Kotlin Collections
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.