Added in API level 1

TableLayout


open class TableLayout : LinearLayout
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ android.widget.LinearLayout
   ↳ android.widget.TableLayout

A layout that arranges its children into rows and columns. A TableLayout consists of a number of android.widget.TableRow objects, each defining a row (actually, you can have other children, which will be explained below). TableLayout containers do not display border lines for their rows, columns, or cells. Each row has zero or more cells; each cell can hold one View object. 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.

The width of a column is defined by the row with the widest cell in that column. However, a TableLayout can specify certain columns as shrinkable or stretchable by calling setColumnShrinkable() or setColumnStretchable(). If marked as shrinkable, the column width can be shrunk to fit the table into its parent object. If marked as stretchable, it can expand in width to fit any extra space. The total width of the table is defined by its parent container. It is important to remember that a column can be both shrinkable and stretchable. In such a situation, the column will change its size to always use up the available space, but never more. Finally, you can hide a column by calling setColumnCollapsed().

The children of a TableLayout cannot specify the layout_width attribute. Width is always MATCH_PARENT. However, the layout_height attribute can be defined by a child; default value is android.widget.TableLayout.LayoutParams#WRAP_CONTENT. If the child is a android.widget.TableRow, then the height is always android.widget.TableLayout.LayoutParams#WRAP_CONTENT.

Cells must be added to a row in increasing column order, both in code and XML. Column numbers are zero-based. If you don't specify a column number for a child cell, it will autoincrement to the next available column. If you skip a column number, it will be considered an empty cell in that row. See the TableLayout examples in ApiDemos for examples of creating tables in XML.

Although the typical child of a TableLayout is a TableRow, you can actually use any View subclass as a direct child of TableLayout. The View will be displayed as a single row that spans all the table columns.

Summary

Nested classes
open

This set of layout parameters enforces the width of each child to be MATCH_PARENT and the height of each child to be WRAP_CONTENT, but only if the height is not specified.

Inherited XML attributes
Inherited constants
Public constructors
TableLayout(context: Context!)

Creates a new TableLayout for the given context.

TableLayout(context: Context!, attrs: AttributeSet!)

Creates a new TableLayout for the given context and with the specified set attributes.

Public methods
open Unit
addView(child: View!)

Adds a child view.

open Unit
addView(child: View!, params: ViewGroup.LayoutParams!)

Adds a child view with the specified layout parameters.

open Unit
addView(child: View!, index: Int)

Adds a child view.

open Unit
addView(child: View!, index: Int, params: ViewGroup.LayoutParams!)

Adds a child view with the specified layout parameters.

open TableLayout.LayoutParams!

Returns a new set of layout parameters based on the supplied attributes set.

open CharSequence!

open Boolean
isColumnCollapsed(columnIndex: Int)

Returns the collapsed state of the specified column.

open Boolean
isColumnShrinkable(columnIndex: Int)

Returns whether the specified column is shrinkable or not.

open Boolean
isColumnStretchable(columnIndex: Int)

Returns whether the specified column is stretchable or not.

open Boolean

Indicates whether all columns are shrinkable or not.

open Boolean

Indicates whether all columns are stretchable or not.

open Unit

Call this when something has changed which has invalidated the layout of this view.

open Unit
setColumnCollapsed(columnIndex: Int, isCollapsed: Boolean)

Collapses or restores a given column.

open Unit
setColumnShrinkable(columnIndex: Int, isShrinkable: Boolean)

Makes the given column shrinkable or not.

open Unit
setColumnStretchable(columnIndex: Int, isStretchable: Boolean)

Makes the given column stretchable or not.

open Unit

Register a callback to be invoked when a child is added to or removed from this view.

open Unit
setShrinkAllColumns(shrinkAllColumns: Boolean)

Convenience method to mark all columns as shrinkable.

open Unit
setStretchAllColumns(stretchAllColumns: Boolean)

Convenience method to mark all columns as stretchable.

Protected methods
open Boolean

open LinearLayout.LayoutParams!

Returns a set of layout parameters with a width of android.view.ViewGroup.LayoutParams#MATCH_PARENT, and a height of android.view.ViewGroup.LayoutParams#WRAP_CONTENT.

open LinearLayout.LayoutParams!

Returns a safe set of layout parameters based on the supplied layout params.

open Unit
onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int)

Called from layout when this view should assign a size and position to each of its children.

open Unit
onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int)

Measure the view and its content to determine the measured width and the measured height.

Inherited functions