TableRow
版本:Android 3.0 r1
类结构
public class TableRowextends LinerLayout
java.lang.Object
android.view.View
android.view.ViewGroup
android.widget.LinearLayout
android.widget.TableRow
类概述
按照水平方向来组织子视图的布局。TableRow应该总是作为TableLayout的子视图。如果TableRow的父视图不是TableLayout,那么TableRow将相当于一个水平方向布局的LinearLayout。
在XML配置文件中TableRow的子视图不需要详细指定其layout_width和layout_height属性值。TableRow总是强制将这两个属性分别赋值为MATCH_PARENT和WRAP_CONTENT。
可参考android.widget.TableRow.LayoutParams的布局属性。
内部类
class TableRow.LayoutParams
适用于TableRow的子视图的属性设置
构造函数
public TableRow(Context
context)
为给定的上下文创建TableRow布局。
参数
context应用程序环境
public TableRow(Context
context, AttributeSet
attrs)
使用指定的属性集合为给定的上下文创建TableRow布局。
参数
context应用程序环境
attrs属性集合
公共方法
public TableRow.LayoutParamsgenerateLayoutParams(AttributeSet
attrs)
返回一组基于提供的属性集合的布局参数集合。
参数
attrs用于生成布局参数的属性集
返回值
ViewGroup.LayoutParams或其子类的实例
public View getVirtualChildAt(int i)
返回指定索引的视图。这个方法被重载时应当考虑到其虚拟子视图。参见TableLayout和TableRow的示例代码。
参数
i子视图的索引
返回值
指定索引的子视图
public intgetVirtualChildCount()
返回虚拟子视图的个数。如果这个布局支持子视图,此数量可能与实际子视图数量不同。参见TableLayout和TableRow的示例代码。
返回值
虚拟子视图的数量
public void setOnHierarchyChangeListener(ViewGroup.OnHierarchyChangeListener
listener)
注册一个回调函数,当从视图中添加或移除子视图时被调用。
参数
listener层次结构变更时执行的回调函数
受保护方法
protected boolean checkLayoutParams(ViewGroup.LayoutParams
p)
(译者注:检测是不是AbsoluteLayout.LayoutParams的实例)
protected LinearLayout.LayoutParamsgenerateDefaultLayoutParams()
返回宽度为MATCH_PARENT,高度为WRAP_CONTENT且没有跨度的布局参数集合。
返回值
默认布局参数集合或空
protected LinearLayout.LayoutParams
generateLayoutParams(ViewGroup.LayoutParams
p)
返回一组合法的受支持的布局参数集合。当一个ViewGroup传递一个布局参数没有通过checkLayoutParams(android.view.ViewGroup.LayoutParams)检测的视图时,此方法将被调用。此方法会返回一组新的适合当前ViewGroup的布局参数,可能从指定的一组布局参数集合中复制适当的属性。
参数
p被转换成一组适合当前ViewGroup的布局参数
返回值
一个ViewGroup.LayoutParams的实例或者其中的一个子节点
protected void onLayout(boolean changed, int
l, int t, int r, int b)
在此视图设置其子视图的大小及位置时调用。派生类可以重写此方法并重新为其子类布局。
参数
changed这是当前视图的一个新大小或位置
l相对于父节点的左边位置
t相对于父节点的顶点位置
r相对于父节点的右边位置
b相对于父节点的底部位置
protected void onMeasure(int
widthMeasureSpec, int heightMeasureSpec)
测量视图及其内容,以确定其宽度和高度。此方法由measure(int,
int)调用。需要被子类重写以提供准确、高效的测量其内容的方法。
约定:当重写此方法时,必须调用setMeasuredDimension(int,
int)来保存当前视图的宽度和高度。如果调用不成功将会导致一个IllegalStateException异常,由measure(int,
int)抛出。要有效的调用父类的onMeasure(int,
int)方法。
基类的实现是以背景大小为默认大小,除非MeasureSpec(测量细则)允许更大的背景。子类应重写onMeasure(int,
int)以对其内容提供更合适的大小。
如果此方法被重写,那么子类要确保其测量高度和测量宽度要大于视图的最小宽度和最小高度(getSuggestedMinimumHeight()和getSuggestedMinimumWidth())。
参数
widthMeasureSpec父视图要求的横向空间大小。该要求由View.MeasureSpec进行编码
heightMeasureSpec父视图要求的纵向空间大小。该要求由View.MeasureSpec进行编码
补充
推荐教程:
Android
Doc官方教程-在TableLayout中使用TableRow
在TableLayout中使用TableRow对象来定义多行