鸿蒙OS开发文档 鸿蒙OS ComponentParent

2024-02-25 开发教程 鸿蒙OS开发文档 匿名 2

ComponentParent

public interface ComponentParent

定义父组件的特征。

此类为组件提供与其父组件交互的接口。

方法总结

修饰符和类型方法描述
intgetChildIndex(Component component)查询子组件的位置。
ComponentParentgetComponentParent()获取子组件的父组件。
voidmoveChildToFront(Component component)调整子组件的 z 顺序,使其位于所有子组件之上。
booleanonDrag(Component component, DragEvent event)检查拖动事件是否分发到父组件。
voidpostLayout()请求父组件重新排列其布局。
voidremoveComponent(Component component)从父组件中移除子组件。
voidremoveComponentAt(int index)从组件列表中的指定位置移除组件。
voidremoveComponents(int start, int count)从组件列表中的指定位置移除所有组件。
ComponentContainer.LayoutConfigverifyLayoutConfig(ComponentContainer.LayoutConfig config)根据当前布局类型验证布局参数。

方法详情

postLayout

void postLayout()

请求父组件重新排列其布局。

getChildIndex

int getChildIndex(Component component)

查询子组件的位置。

参数:

参数名称参数描述
component指示要查询的子组件。

返回:

返回一个正整数,表示子组件在父组件中的位置; 如果子组件不包含在父组件中,则返回 -1。

removeComponent

void removeComponent(Component component)

从父组件中移除子组件。

参数:

参数名称参数描述
component指示要移除的子组件。

removeComponentAt

void removeComponentAt(int index)

从组件列表中的指定位置移除组件。

参数:

参数名称参数描述
index指示要移除的组件的位置索引。

removeComponents

void removeComponents(int start, int count)

从组件列表中的指定位置移除所有组件。

参数:

参数名称参数描述
start表示第一个移除的组件的位置索引。
count表示要移除的组件数量。

verifyLayoutConfig

ComponentContainer.LayoutConfig verifyLayoutConfig(ComponentContainer.LayoutConfig config)

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

参数:

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

返回:

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

getComponentParent

ComponentParent getComponentParent()

获取子组件的父组件。

返回:

返回子组件的父组件。

moveChildToFront

void moveChildToFront(Component component)

调整子组件的 z 顺序,使其位于所有子组件之上。

z 顺序调整会更改顺序相关的布局。

参数:

参数名称参数描述
component指示要移动到所有子组件顶部的子组件。

onDrag

boolean onDrag(Component component, DragEvent event)

检查拖动事件是否分发到父组件。

参数:

参数名称参数描述
component表示接收拖动事件的组件。
event指示 DragEvent 对象。

返回:

如果拖动事件已经被父组件处理,则返回 true; 否则返回 false。