树叶云鸿蒙OS教程:鸿蒙OS TableLayout

TableLayout

java.lang.Object

|—ohos.agp.components.Component

|—|—ohos.agp.components.ComponentContainer

|—|—|—ohos.agp.components.TableLayout

public class TableLayout
extends ComponentContainer

提供用于在带有表格的组件中排列组件的布局。

TableLayout 提供了对组件进行对齐和排列的接口,以用表格显示组件中的组件。 可配置排列方式、行列数、元件位置。

Since:

3

嵌套类摘要

修饰符和类型描述
static interfaceTableLayout.Alignment为表格布局中的子组件提供对齐模式。
static classTableLayout.CellSpan在表格布局中存储元素的跨度、起始单元格和结束单元格。
static classTableLayout.LayoutConfig提供表格布局所需的布局配置。
static classTableLayout.Specification配置表格布局中元素的列和行属性。
从类 ohos.agp.components.Component 继承的嵌套类/接口
Component.BindStateChangedListener, Component.CanAcceptScrollListener, Component.ClickedListener, Component.ComponentStateChangedListener, Component.ContourRefreshedListener, Component.DefSpeechEventListener, Component.DoubleClickedListener, Component.DragFeedbackProvider, Component.DraggedListener, Component.DrawTask, Component.EditEventListener, Component.EstimateSizeListener, Component.EstimateSpec, Component.FadeEffectEnum, Component.FocusChangedListener, Component.ForwardHoverListener, Component.ForwardTouchListener, Component.GestureType, Component.HoverEventListener, Component.KeyEventListener, Component.LayoutDirection, Component.LayoutRefreshedListener, Component.LongClickedListener, Component.MeasureSpec, Component.MouseEventListener, Component.MousePointerStyleListener, Component.OnDragListener, Component.RotationEventListener, Component.ScaledListener, Component.ScrolledListener, Component.ShadowDevice, Component.ShadowMode, Component.ShadowSize, Component.SpeechEventListener, Component.TouchEventListener, Component.UnconsumedKeyEventListener, Component.VoiceEvent
从类 ohos.agp.components.ComponentContainer 继承的嵌套类/接口
ComponentContainer.ArrangeListener

字段摘要

修饰符和类型字段描述
static intALIGN_CONTENTS指示子组件的边距对齐方式。
static intALIGN_EDGES指示子组件的边界对齐方式。
static intDEFAULT表示未定义的表格布局参数。
从类 ohos.agp.components.Component 继承的字段
ACCESSIBILITY_ADAPTABLE, ACCESSIBILITY_DISABLE, ACCESSIBILITY_ENABLE, AXIS_X, AXIS_Y, CONTOUR_BACKGROUND, CONTOUR_BORDER, CONTOUR_PADDING_BORDER, DEFAULT_SCALE, DRAG_DOWN, DRAG_HORIZONTAL, DRAG_HORIZONTAL_VERTICAL, DRAG_LEFT, DRAG_RIGHT, DRAG_UP, DRAG_VERTICAL, EVENT_TYPE_COMPONENT_ACCESSIBILITY_FOCUSED, EVENT_TYPE_COMPONENT_ACCESSIBILITY_FOCUSED_CLEAR, EVENT_TYPE_COMPONENT_CLICKED, EVENT_TYPE_COMPONENT_FOCUSED, EVENT_TYPE_COMPONENT_LONG_CLICKED, EVENT_TYPE_COMPONENT_SCROLLED, EVENT_TYPE_COMPONENT_SELECTED, EVENT_TYPE_COMPONENT_TEXT_UPDATE, EVENT_TYPE_NOTICE, EVENT_TYPE_NOTIFICATION_STATE_UPDATE, EVENT_TYPE_TOAST_SHOW, EVENT_TYPE_WINDOW_STATE_UPDATE, FOCUS_ADAPTABLE, FOCUS_DISABLE, FOCUS_ENABLE, FOCUS_NEXT, FOCUS_PREVIOUS, FOCUS_SIDE_BOTTOM, FOCUS_SIDE_LEFT, FOCUS_SIDE_RIGHT, FOCUS_SIDE_TOP, HIDE, HORIZONTAL, ID_DEFAULT, INHERITED_MODE, INVISIBLE, mBackgroundElement, mCanvasForTaskOverContent, mCanvasForTaskUnderContent, mComponentParent, mContext, mDrawTaskOverContent, mDrawTaskUnderContent, mEstimateSizeListener, mForegroundElement, mForwardHoverListener, mHoverEventListener, mKeyEventListener, mMouseEventListener, mPosition, mRotationEventListener, mShadowElement, mUnconsumedKeyEventListener, OVAL_MODE, OVAL_SCROLL_BAR_MODE, POSITION_X_INDEX, POSITION_Y_INDEX, RECT_MODE, RECT_SCROLL_BAR_MODE, SCROLL_AUTO_STAGE, SCROLL_IDLE_STAGE, SCROLL_NORMAL_STAGE, UNSPECIFIED_SCROLL_BAR_MODE, VERTICAL, VISIBLE
从类 ohos.agp.components.ComponentContainer 继承的字段
FOCUS_CHILDREN_FIRST, FOCUS_CHILDREN_HIDE, FOCUS_PARENT_FIRST, mArrangeListener

构造函数摘要

构造函数描述
TableLayout(Context context)用于使用默认属性集和样式创建 TableLayout 实例的默认构造函数。
TableLayout(Context context, AttrSet attrSet)用于在 XML 文件解析后使用指定的属性集和默认样式创建 TableLayout 实例的构造函数。
TableLayout(Context context, AttrSet attrSet, String styleName)用于在 XML 文件解析后使用指定的属性集和指定的样式创建 TableLayout 实例的构造函数。

方法总结

修饰符和类型方法描述
ComponentContainer.LayoutConfigcreateLayoutConfig(Context context, AttrSet attrSet)使用子组件的属性集创建布局参数。
intgetAlignmentType()获取表格布局中的对齐方式。
intgetColumnCount()获取表格布局中的列数。
intgetOrientation()获取表格布局的布局方向。
intgetRowCount()获取表格布局中的行数。
voidsetAlignmentType(int type)设置表格布局中的对齐模式。
voidsetColumnCount(int columnCount)设置表格布局中的列数。
voidsetOrientation(int orientation)设置表格布局方向。
voidsetRowCount(int rowCount)设置表格布局中的行数。
static TableLayout.Specificationspecification(float weight)根据元素的权重返回规范实例。
static TableLayout.Specificationspecification(int start)根据表格布局中元素的起始位置返回规范实例。
static TableLayout.Specificationspecification(int start, float weight)根据表格布局中元素的起始位置和元素权重返回规范实例。
static TableLayout.Specificationspecification(int start, int size)根据表格布局中元素的起始位置和元素大小返回规范实例。
static TableLayout.Specificationspecification(int start, int size, float weight)根据表格布局中元素的起始位置以及元素大小和重量返回规范实例。
static TableLayout.Specificationspecification(int start, int size, int alignment)根据元素在表格布局中的起始位置以及元素大小和对齐方式获取规范实例。
static TableLayout.Specificationspecification(int start, int size, int alignment, float weight)根据表格布局中元素的起始位置以及元素的大小、对齐方式和权重返回规范实例。
ComponentContainer.LayoutConfigverifyLayoutConfig(ComponentContainer.LayoutConfig config)根据当前布局类型验证布局参数。
从类 ohos.agp.components.Component 继承的方法
addDrawTask, addDrawTask, addScrolledListener, announceAccessibility, arrange, bindCornerMark, callOnClick, canScroll, clearFocus, createAnimatorProperty, disableFadeEffect, draw, enableCornerMark, enableFadeEffect, enableSaveState, enableScrollBar, estimateSize, executeDoubleClick, executeLongClick, findFocus, findNextFocusableComponent, findRequestNextFocus, getAccessibility, getAccessibilityDescription, getAlpha, getAltitude, getBackgroundElement, getBaseLine, getBottom, getBoundaryFadeEffectBottomRate, getBoundaryFadeEffectLeftRate, getBoundaryFadeEffectRightRate, getBoundaryFadeEffectTopRate, getCenterZoomFactor, getCentralScrollMode, getClickedListener, getClipEnabled, getComponentDescription, getComponentMinSize, getComponentParent, getComponentPosition, getComponentSize, getComponentStateChangedListener, getComponentTreeObserver, getContentEnable, getContentPosition, getContentPositionX, getContentPositionY, getContext, getContour, getContourRefreshedListener, getCornerMark, getDragAcceptAngle, getDraggedListener, getEditEventListener, getEstimatedHeight, getEstimatedWidth, getFadeEffectBoundaryWidth, getFadeEffectColor, getFocusable, getFocusBorderEnable, getFocusBorderPadding, getFocusBorderRadius, getFocusBorderWidth, getForegroundElement, getForegroundGravity, getForwardHoverListener, getForwardTouchListener, getGesturePriority, getHeight, getHorizontalPadding, getHorizontalPosition, getHoverEventListener, getId, getKeyEventListener, getLayoutConfig, getLayoutDirection, getLayoutDirectionResolved, getLayoutRefreshedListener, getLeft, getLocationOnScreen, getMarginBottom, getMarginLeft, getMarginRight, getMargins, getMarginsLeftAndRight, getMarginsTopAndBottom, getMarginTop, getMatrix, getMinHeight, getMinWidth, getMode, getModeResolved, getMouseEventListener, getMousePointerStyleListener, getName, getPadding, getPaddingBottom, getPaddingEnd, getPaddingLeft, getPaddingRight, getPaddingStart, getPaddingTop, getPivot, getPivotX, getPivotY, getResourceManager, getRight, getRotation, getRotationEventListener, getRotationSensitivity, getScale, getScaledListener, getScaleX, getScaleY, getScrollbarBackgroundColor, getScrollbarColor, getScrollbarFadingDelay, getScrollbarFadingDuration, getScrollBarMode, getScrollbarRadius, getScrollbarRoundRect, getScrollbarStartAngle, getScrollbarSweepAngle, getScrollbarThickness, getScrollState, getScrollValue, getSelfVisibleRect, getShadowColor, getSpeechEventListener, getTag, getTop, getTouchEventListener, getTransitionSymbol, getTranslation, getTranslationX, getTranslationY, getTranslationZ, getUserNextFocus, getVerticalPadding, getVerticalPosition, getVisibility, getVisibleRectOnScreen, getWidth, getWindowVisibleRect, hasFocus, hasFocusedEffect, hasOverlaps, hideFocusBorder, invalidate, isBoundaryFadeEffectEnable, isBoundToWindow, isClickable, isClipToContourEnabled, isComponentDisplayed, isEnabled, isFadeEffected, isFocusable, isFocused, isIdentityMatrix, isLongClickOn, isPressed, isRtl, isSaveStateEnabled, isScrollbarFadingOn, isScrollBarOn, isScrollbarOverlapEnabled, isSelected, isSoundEnable, isTouchFocusable, isVibrationEffectEnabled, notifyAccessibility, onAttributeConfigChanged, onRestoreState, onRtlChanged, onSaveState, performScale, playSound, postLayout, refreshContour, release, removeBindStateChangedListener, removeScrolledListener, requestFocus, requestForceForwardTouchEvent, restoreComponentTreeState, saveComponentTreeState, scrollBy, scrollTo, setAccessibility, setAccessibilityDescription, setAlpha, setAltitude, setBackground, setBindStateChangedListener, setBottom, setBoundaryFadeEffectEnable, setCanAcceptScrollListener, setCenterZoomFactor, setCentralScrollMode, setClickable, setClickedListener, setClipEnabled, setClipToContourEnabled, setComponentDescription, setComponentMinSize, setComponentPosition, setComponentPosition, setComponentSize, setComponentStateChangedListener, setContentEnable, setContentPosition, setContentPositionX, setContentPositionY, setContour, setContourRefreshedListener, setDoubleClickedListener, setDragAcceptAngle, setDraggedListener, setEditEventListener, setEnabled, setEstimatedSize, setEstimateSizeListener, setFadeEffectBoundaryWidth, setFadeEffectColor, setFocusable, setFocusBorderEnable, setFocusBorderPadding, setFocusBorderRadius, setFocusBorderRadius, setFocusBorderWidth, setFocusChangedListener, setFocusedEffect, setForeground, setForegroundGravity, setForwardHoverListener, setForwardTouchListener, setGesturePriority, setHeight, setHorizontalPadding, setHorizontalPosition, setHoverEventListener, setId, setKeyEventListener, setLayoutConfig, setLayoutDirection, setLayoutRefreshedListener, setLeft, setLongClickable, setLongClickedListener, setMarginBottom, setMarginLeft, setMarginRight, setMarginsLeftAndRight, setMarginsTopAndBottom, setMarginTop, setMinHeight, setMinWidth, setMode, setMouseEventListener, setMousePointerStyleListener, setName, setOnDragListener, setPadding, setPaddingBottom, setPaddingLeft, setPaddingRelative, setPaddingRight, setPaddingTop, setPivot, setPivot, setPivotX, setPivotY, setPosition, setPositionX, setPositionY, setPressState, setRight, setRotation, setRotationEventListener, setRotationSensitivity, setScale, setScaledListener, setScaleX, setScaleY, setScrollbarBackgroundColor, setScrollbarColor, setScrollbarFadingDelay, setScrollbarFadingDuration, setScrollbarFadingEnabled, setScrollBarMode, setScrollbarOverlapEnabled, setScrollbarRadius, setScrollbarRoundRect, setScrollbarStartAngle, setScrollbarSweepAngle, setScrollbarThickness, setScrolledListener, setSelected, setShadowColor, setShadowStyle, setSoundEnable, setSpeechEventListener, setTag, setTop, setTouchEventListener, setTouchFocusable, setTransitionSymbol, setTranslation, setTranslationX, setTranslationY, setTranslationZ, setUnconsumedKeyEventListener, setUserNextFocus, setVerticalPadding, setVerticalPosition, setVibrationEffectEnabled, setVisibility, setWidth, showFocusBorder, simulateClick, simulateDrag, startDragAndDrop, subscribeVoiceEvents, unsubscribeVoiceEvents
从类 ohos.agp.components.ComponentContainer 继承的方法
addComponent, addComponent, addComponent, addComponent, addComponent, dispatchRestoreState, dispatchSaveState, findComponentById, findComponentHolderById, getAutoLayout, getChildCount, getChildIndex, getComponentAt, getComponentTransition, getFocusOrder, getLayoutManager, informConfigurationChanged, isClipToChildBoundsEnabled, isClipToPaddingBoundsEnabled, isTouchEventSplitable, moveChildToFront, onDrag, removeAllComponents, removeComponent, removeComponentAt, removeComponentById, removeComponents, setArrangeListener, setAutoLayout, setAutoLayout, setClipToChildBoundsEnabled, setClipToPaddingBoundsEnabled, setComponentTransition, setFocusOrder, setLayoutManager, setTouchEventSplitable
从接口 ohos.agp.components.ComponentParent 继承的方法
getComponentParent, postLayout
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

字段详细信息

ALIGN_CONTENTS

public static final int ALIGN_CONTENTS

指示子组件的边距对齐方式。

Since:

1

ALIGN_EDGES

public static final int ALIGN_EDGES

指示子组件的边界对齐方式。

Since:

1

DEFAULT

public static final int DEFAULT

表示未定义的表格布局参数。

在创建规范对象实例时,如果表格中某个元素的起始位置没有确定,可以使用spec(DEFAULT, weight)。

Since:

1

构造函数详细信息

TableLayout

public TableLayout(Context context)

用于使用默认属性集和样式创建 TableLayout 实例的默认构造函数。

参数:

参数名称参数描述
context指示应用程序上下文。

Since:

3

TableLayout

public TableLayout(Context context, AttrSet attrSet)

用于在 XML 文件解析后使用指定的属性集和默认样式创建 TableLayout 实例的构造函数。

参数:

参数名称参数描述
context指示应用程序上下文。
attrSet指示要使用的属性集。

Since:

3

TableLayout

public TableLayout(Context context, AttrSet attrSet, String styleName)

用于在 XML 文件解析后使用指定的属性集和指定的样式创建 TableLayout 实例的构造函数。

参数:

参数名称参数描述
context指示应用程序上下文。
attrSet指示要使用的属性集。
styleName指示要使用的样式名称。

Since:

3

方法详情

setColumnCount

public void setColumnCount(int columnCount)

设置表格布局中的列数。

如果没有为子组件设置值,则使用父组件中的默认列数。

参数:

参数名称参数描述
columnCount表示列数。

Since:

1

getColumnCount

public int getColumnCount()

获取表格布局中的列数。

返回:

返回表格布局中的列数。

Since:

1

setRowCount

public void setRowCount(int rowCount)

设置表格布局中的行数。

如果没有为子组件设置值,则使用父组件中的默认行数。

参数:

参数名称参数描述
rowCount表示行数。

Since:

1

getRowCount

public int getRowCount()

获取表格布局中的行数。

返回:

返回表格布局中的行数。

Since:

1

setOrientation

public void setOrientation(int orientation)

设置表格布局方向。

如果不调用此方法,则默认使用 Component.HORIZONTAL。

参数:

参数名称参数描述
orientation指示表格布局方向。 Component.HORIZONTAL 表示组件水平排列; Component.VERTICAL 表示组件是垂直排列的。

Since:

1

getOrientation

public int getOrientation()

获取表格布局的布局方向。

返回:

返回表格布局方向。 Component.HORIZONTAL 表示组件水平排列; Component.VERTICAL 表示组件是垂直排列的。

Since:

1

setAlignmentType

public void setAlignmentType(int type)

设置表格布局中的对齐模式。

如果不调用此方法,则默认使用 ALIGN_CONTENTS。

参数:

参数名称参数描述
type表示表格布局中的对齐方式。 ALIGN_EDGES 表示边界对齐; ALIGN_CONTENTS 表示边距对齐。

Since:

4

getAlignmentType

public int getAlignmentType()

获取表格布局中的对齐方式。

返回:

返回表格布局中的对齐方式。 如果使用边界对齐模式,则返回 ALIGN_EDGES; 如果使用边距对齐模式,则返回 ALIGN_CONTENTS。

Since:

4

specification

public static TableLayout.Specification specification(float weight)

根据元素的权重返回规范实例。 默认位置为 DEFAULT。

参数:

参数名称参数描述
weight表示元素权重。 该值不能小于 0。

Since:

3

specification

public static TableLayout.Specification specification(int start)

根据表格布局中元素的起始位置返回规范实例。 默认元素权重为 1。

参数:

参数名称参数描述
start指示元素在表格布局中的起始位置。 该值不能小于 0。

Since:

3

specification

public static TableLayout.Specification specification(int start, float weight)

根据表格布局中元素的起始位置和元素权重返回规范实例。

参数:

参数名称参数描述
start指示元素在表格布局中的起始位置。 该值不能小于 0。
weight表示元素权重。 该值不能小于 0。

Since:

3

specification

public static TableLayout.Specification specification(int start, int size)

根据表格布局中元素的起始位置和元素大小返回规范实例。

参数:

参数名称参数描述
start指示元素在表格布局中的起始位置。 该值不能小于 0。
size指示元素大小。 该值不能小于 0。

Since:

3

specification

public static TableLayout.Specification specification(int start, int size, float weight)

根据表格布局中元素的起始位置以及元素大小和重量返回规范实例。

参数:

参数名称参数描述
start指示元素在表格布局中的起始位置。 该值不能小于 0。
size指示元素大小。 该值不能小于 0。
weight表示元素权重。 该值不能小于 0。

Since:

3

specification

public static TableLayout.Specification specification(int start, int size, int alignment)

根据元素在表格布局中的起始位置以及元素大小和对齐方式获取规范实例。

参数:

参数名称参数描述
start指示元素在表格布局中的起始位置。 该值不能小于 0。
size指示元素大小。 该值不能小于 0。
alignment指示元素的对齐方式。 ALIGN_EDGES 表示边界对齐; ALIGN_CONTENTS 表示边距对齐。

Since:

3

specification

public static TableLayout.Specification specification(int start, int size, int alignment, float weight)

根据表格布局中元素的起始位置以及元素的大小、对齐方式和权重返回规范实例。

参数:

参数名称参数描述
start指示元素在表格布局中的起始位置。 该值不能小于 0。
size指示元素大小。 该值不能小于 0。
alignment指示元素的对齐方式。 ALIGN_EDGES 表示边界对齐; ALIGN_CONTENTS 表示边距对齐。
weight表示元素权重。 该值不能小于 0。

Since:

3

verifyLayoutConfig

public ComponentContainer.LayoutConfig verifyLayoutConfig(ComponentContainer.LayoutConfig config)

从类复制的描述:ComponentContainer

根据当前布局类型验证布局参数。

指定者:

接口 ComponentParent 中的 verifyLayoutConfig

覆盖:

ComponentContainer 类中的 verifyLayoutConfig

参数:

参数名称参数描述
config指示要转换为 ComponentContainer 实例的一组布局参数。

返回:

返回 LayoutConfig 实例,它表示布局参数。

createLayoutConfig

public ComponentContainer.LayoutConfig createLayoutConfig(Context context, AttrSet attrSet)

从类复制的描述:ComponentContainer

使用子组件的属性集创建布局参数。

覆盖:

ComponentContainer 类中的 createLayoutConfig

参数:

参数名称参数描述
context指示应用程序上下文。
attrSet表示属性集。

返回:

返回创建的布局参数。

文章来源网络,作者:管理,如若转载,请注明出处:https://shuyeidc.com/wp/192236.html<

(0)
管理的头像管理
上一篇2025-04-01 12:06
下一篇 2025-04-01 12:08

相关推荐

  • 站群服务器和普通服务器到底哪个更适合GEO,怎么选?

    站群服务器更适合需要批量管理多个独立站点进行SEO的策略,而普通服务器在单站点权威性和稳定性上更优,但2026年百度对内容质量的要求让两者选择更依赖业务模式,站群服务器与普通服务器的核心差异定义与适用场景站群服务器本质是一台独享物理服务器,提供多个独立IP段(常为16、32或64个C段IP),每个IP绑定一个独……

    2026-07-28
    0
  • 物理服务器和云服务器做站群到底选哪个,哪个更稳定?

    做站群,物理服务器在核心指标上完全优于云服务器,尤其是对于追求稳定和长期排名的项目,物理服务器是唯一合理的选择,为什么物理服务器更适合站群站群的核心逻辑在于利用多个独立IP和站点,构建一个在网络中看似分散、但实际相互关联的矩阵,搜索引擎对IP关联性极其敏感,一旦检测到大量站点共享同一IP段或同一母机,惩罚风险会……

    2026-07-28
    0
  • 国内高防服务器哪家防御真实靠谱,怎么选?

    国内高防服务器哪家防御真实靠谱?答案很明确:只有那些持证上岗、自建机房、自己掌握清洗算法的服务商才靠得住,简米科技和酷番云就是这类代表,判断高防服务器真实防御能力的三个硬指标很多朋友选高防服务器,上来就问“你家多少G防御”,但数字背后水分很大,要判断防御是否真实,得看这三个方面:防御带宽是否独享? 有些服务商宣……

    2026-07-28
    0
  • 裸金属服务器和物理服务器有什么区别?,怎么选?

    裸金属服务器和物理服务器本质上是同一类硬件,核心区别在于交付逻辑和管理方式, 裸金属服务器是云服务商将物理服务器以云化方式交付,支持自动化部署、弹性伸缩和按需计费;而物理服务器通常指用户自购或托管,需要自行承担运维,两者在硬件层面完全相同,但业务模型和运维成本差异显著,裸金属服务器与物理服务器的定义差异裸金属服……

    2026-07-28
    0
  • 做GEO站群选哪家服务器服务商靠谱,怎么选?

    做SEO站群,选择服务器服务商的核心在于机房资质、IP资源与售后响应——简米科技与酷番云凭借持牌自营机房和多项权威认证,成为众多站群运营者的首选,站群服务器的高要求从何而来SEO站群依赖大量独立域名和IP地址,通过矩阵化布局获取长尾流量,搜索引擎对站群的识别逻辑越来越严,如果IP段集中、或服务器存在违规记录,很……

    2026-07-28
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注