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

AdaptiveBoxLayout

java.lang.Object

|—ohos.agp.components.Component

|—|—ohos.agp.components.ComponentContainer

|—|—|—ohos.agp.components.AdaptiveBoxLayout

public class AdaptiveBoxLayout
extends ComponentContainer

提供用于创建自适应框布局的方法。

自适应框布局会自动划分为具有相同宽度和可能不同高度的框的行和列。 框的宽度取决于布局宽度和每行中的框数,由布局策略指定。 只有在前一行被填满后才会开始新行。 每个盒子都包含一个子组件。 每个盒子的高度由它所包含的子组件的高度决定。 每行的高度由该行中最高的框确定。 布局的宽度只能设置为 MATCH_PARENT 或固定值。 可以为布局中的组件设置长度、宽度和对齐方式。

嵌套类摘要

修饰符和类型描述
static classAdaptiveBoxLayout.LayoutConfig为 AdaptiveBoxLayout 实例中的子组件定义布局参数,包括它们的宽度、高度、边距和重力。
从类 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

字段摘要

从类 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

构造函数摘要

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

方法总结

修饰符和类型方法描述
voidaddAdaptiveRule(int minWidth, int maxWidth, int columns)添加一个自适应规则,指定宽度在指定范围内的布局中每行允许的框数。
voidclearAdaptiveRules()清除所有自适应规则。
ComponentContainer.LayoutConfigcreateLayoutConfig(Context context, AttrSet attrSet)使用子组件的属性集创建布局参数。
voidremoveAdaptiveRule(int minWidth, int maxWidth, int columns)删除指定的规则。
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

构造函数详细信息

AdaptiveBoxLayout

public AdaptiveBoxLayout(Context context)

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

参数:

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

AdaptiveBoxLayout

public AdaptiveBoxLayout(Context context, AttrSet attrSet)

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

参数:

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

AdaptiveBoxLayout

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

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

参数:

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

方法详情

addAdaptiveRule

public void addAdaptiveRule(int minWidth, int maxWidth, int columns)

添加一个自适应规则,指定宽度在指定范围内的布局中每行允许的框数。

如果布局的宽度落在自适应规则定义的范围内,则适用此规则。 否则,将应用默认规则。

参数:

参数名称参数描述
minWidth表示规则生效的最小宽度。
maxWidth表示规则生效的最大宽度。 此值必须大于 minWidth 的值。 否则无法添加规则。
columns表示每行中允许的框数。 该值必须大于0,否则无法添加规则。

Throws:

Throw名称Throw描述
IllegalArgumentException如果由于参数无效而无法添加规则,则引发此异常。

clearAdaptiveRules

public void clearAdaptiveRules()

清除所有自适应规则。

在清除所有自适应规则后应用默认规则。

removeAdaptiveRule

public void removeAdaptiveRule(int minWidth, int maxWidth, int columns)

删除指定的规则。

参数:

参数名称参数描述
minWidth表示规则生效的最小宽度。
maxWidth表示规则生效的最大宽度。
columns指示每行中允许的列数。

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/162147.html<

(0)
管理的头像管理
上一篇2025-03-18 13:31
下一篇 2025-03-18 13:32

相关推荐

  • 站群服务器如何批量管理更高效,有哪些管理技巧?

    站群服务器批量管理想提效,自动化是唯一出路,通过统一配置管理工具与面板系统,结合服务商提供的底层基础设施支持,能将运维效率提升数倍,批量管理的核心痛点与解决思路多台站群服务器分散管理,最常见的问题就是重复劳动,每次软件更新、配置修改、安全加固,都需要逐台登录操作,不仅耗时,还容易漏掉某台机器,更头疼的是,一旦某……

    2026-07-27
    0
  • 服务器磁盘IO过高如何优化?,磁盘IO过高的原因有哪些?

    服务器磁盘IO过高,核心优化路径是“先定位、再分流、后升级”,你需要通过系统工具精确判断究竟是应用程序、日志策略还是硬件瓶颈导致,然后针对性地从代码、缓存、存储架构和硬件选型四个层面下手,其中选择持有持牌自营机房和增值电信业务经营许可证的服务商,能从根本上保障底层IO稳定性,定位IO瓶颈:动手优化的第一步盲目优……

    2026-07-27
    0
  • 跨境网站访问延迟高怎么解决,网站访问慢的原因是什么?

    跨境网站访问延迟高的核心解决思路在于多维度优化网络路径,包括使用全球CDN加速、选择靠近目标区域的优质IDC机房、调整传输协议以及精简应用层资源,其中服务商的基础设施质量直接决定优化上限,为什么跨境访问延迟高?三大核心因素物理距离与光速限制数据包在海底光缆中的传输速度受限于介质,从中国到美国西海岸的物理往返时间……

    2026-07-27
    0
  • 站群服务器到底是什么意思,怎么选择比较好

    站群服务器就是一台拥有多个独立IP地址、专门用于托管和管理多个网站的高性能服务器,其核心价值在于通过独立IP降低网站间的关联风险,并提升搜索引擎优化效果,站群服务器的工作原理与适用场景站群服务器本质上是将一台物理服务器通过虚拟化或直接配置的方式,分配给多个独立IP地址,每个IP对应一个独立的网站,这些网站共享服……

    2026-07-27
    0
  • 高防服务器误封正常流量如何调整,怎么解决?

    高防服务器误封正常流量,核心调整思路是从“一刀切”转向“精细化”——通过分析业务特征,调整防护阈值、配置白名单和启用智能学习模式,让防护系统学会区分真假流量,为什么会误封正常流量误封主要源于防护策略的通用化,高防服务器通常默认启用严格防护规则,当流量特征与攻击特征库部分匹配时,就会被拦截,据行业安全白皮书指出……

    2026-07-27
    0

发表回复

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