Android APIs
public class

TableRow

extends LinearLayout
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.LinearLayout
         ↳ android.widget.TableRow

Class Overview

A layout that arranges its children horizontally. A TableRow should always be used as a child of a TableLayout. If a TableRow's parent is not a TableLayout, the TableRow will behave as an horizontal LinearLayout.

The children of a TableRow do not need to specify the layout_width and layout_height attributes in the XML file. TableRow always enforces those values to be respectively MATCH_PARENT and WRAP_CONTENT.

Also see android.widget.TableRow.LayoutParams for layout attributes

Summary

Nested Classes
class TableRow.LayoutParams

Set of layout parameters used in table rows. 

[Expand]
Inherited XML Attributes
From class android.widget.LinearLayout
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Constants
From class android.widget.LinearLayout
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
TableRow(Context context)

Creates a new TableRow for the given context.

TableRow(Context context, AttributeSet attrs)

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

Public Methods
TableRow.LayoutParams generateLayoutParams(AttributeSet attrs)
Returns a new set of layout parameters based on the supplied attributes set.
CharSequence getAccessibilityClassName()
Return the class name of this object to be used for accessibility purposes.
View getVirtualChildAt(int i)

Returns the view at the specified index.

int getVirtualChildCount()

Returns the virtual number of children.

void setOnHierarchyChangeListener(ViewGroup.OnHierarchyChangeListener listener)
Register a callback to be invoked when a child is added to or removed from this view.
Protected Methods
boolean checkLayoutParams(ViewGroup.LayoutParams p)
LinearLayout.LayoutParams generateDefaultLayoutParams()
Returns a set of layout parameters with a width of MATCH_PARENT, a height of WRAP_CONTENT and no spanning.
LinearLayout.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p)
Returns a safe set of layout parameters based on the supplied layout params.
void onLayout(boolean changed, int l, int t, int r, int b)
Called from layout when this view should assign a size and position to each of its children.
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

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

[Expand]
Inherited Methods
From class android.widget.LinearLayout
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.view.ViewParent
From interface android.view.ViewManager
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource

Public Constructors

public TableRow (Context context)

Added in API level 1

Creates a new TableRow for the given context.

Parameters
context Context: the application environment

public TableRow (Context context, AttributeSet attrs)

Added in API level 1

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

Parameters
context Context: the application environment
attrs AttributeSet: a collection of attributes

Public Methods

public TableRow.LayoutParams generateLayoutParams (AttributeSet attrs)

Added in API level 1

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

Parameters
attrs AttributeSet: the attributes to build the layout parameters from
Returns
TableRow.LayoutParams an instance of ViewGroup.LayoutParams or one of its descendants

public CharSequence getAccessibilityClassName ()

Added in API level 23

Return the class name of this object to be used for accessibility purposes. Subclasses should only override this if they are implementing something that should be seen as a completely new class of view when used by accessibility, unrelated to the class it is deriving from. This is used to fill in AccessibilityNodeInfo.setClassName.

Returns
CharSequence

public View getVirtualChildAt (int i)

Added in API level 1

Returns the view at the specified index. This method can be overriden to take into account virtual children. Refer to TableLayout and TableRow for an example.

Parameters
i int: the child's index
Returns
View the child at the specified index

public int getVirtualChildCount ()

Added in API level 1

Returns the virtual number of children. This number might be different than the actual number of children if the layout can hold virtual children. Refer to TableLayout and TableRow for an example.

Returns
int the virtual number of children

public void setOnHierarchyChangeListener (ViewGroup.OnHierarchyChangeListener listener)

Added in API level 1

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

Parameters
listener ViewGroup.OnHierarchyChangeListener: the callback to invoke on hierarchy change

Protected Methods

protected boolean checkLayoutParams (ViewGroup.LayoutParams p)

Added in API level 1

Parameters
p ViewGroup.LayoutParams
Returns
boolean

protected LinearLayout.LayoutParams generateDefaultLayoutParams ()

Added in API level 1

Returns a set of layout parameters with a width of MATCH_PARENT, a height of WRAP_CONTENT and no spanning.

Returns
LinearLayout.LayoutParams a set of default layout parameters or null

protected LinearLayout.LayoutParams generateLayoutParams (ViewGroup.LayoutParams p)

Added in API level 1

Returns a safe set of layout parameters based on the supplied layout params. When a ViewGroup is passed a View whose layout params do not pass the test of checkLayoutParams(android.view.ViewGroup.LayoutParams), this method is invoked. This method should return a new set of layout params suitable for this ViewGroup, possibly by copying the appropriate attributes from the specified set of layout params.

Parameters
p ViewGroup.LayoutParams: The layout parameters to convert into a suitable set of layout parameters for this ViewGroup.
Returns
LinearLayout.LayoutParams an instance of ViewGroup.LayoutParams or one of its descendants

protected void onLayout (boolean changed, int l, int t, int r, int b)

Added in API level 1

Called from layout when this view should assign a size and position to each of its children. Derived classes with children should override this method and call layout on each of their children.

Parameters
changed boolean: This is a new size or position for this view
l int: Left position, relative to parent
t int: Top position, relative to parent
r int: Right position, relative to parent
b int: Bottom position, relative to parent

protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)

Added in API level 1

Measure the view and its content to determine the measured width and the measured height. This method is invoked by measure(int, int) and should be overridden by subclasses to provide accurate and efficient measurement of their contents.

CONTRACT: When overriding this method, you must call setMeasuredDimension(int, int) to store the measured width and height of this view. Failure to do so will trigger an IllegalStateException, thrown by measure(int, int). Calling the superclass' onMeasure(int, int) is a valid use.

The base class implementation of measure defaults to the background size, unless a larger size is allowed by the MeasureSpec. Subclasses should override onMeasure(int, int) to provide better measurements of their content.

If this method is overridden, it is the subclass's responsibility to make sure the measured height and width are at least the view's minimum height and width (getSuggestedMinimumHeight() and getSuggestedMinimumWidth()).

Parameters
widthMeasureSpec int: horizontal space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.
heightMeasureSpec int: vertical space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.