Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
4dcb0b5d
D
Docs
项目概览
OpenHarmony
/
Docs
接近 2 年 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
4dcb0b5d
编写于
10月 26, 2022
作者:
O
openharmony_ci
提交者:
Gitee
10月 26, 2022
浏览文件
操作
浏览文件
下载
差异文件
!11037 improve custom layout doc
Merge pull request !11037 from guozejun/master
上级
73946f24
29bf7e94
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
98 addition
and
12 deletion
+98
-12
zh-cn/application-dev/ui/figures/customLayout.png
zh-cn/application-dev/ui/figures/customLayout.png
+0
-0
zh-cn/application-dev/ui/ui-ts-custom-component-lifecycle-callbacks.md
...tion-dev/ui/ui-ts-custom-component-lifecycle-callbacks.md
+98
-12
未找到文件。
zh-cn/application-dev/ui/figures/customLayout.png
0 → 100644
浏览文件 @
4dcb0b5d
6.0 KB
zh-cn/application-dev/ui/ui-ts-custom-component-lifecycle-callbacks.md
浏览文件 @
4dcb0b5d
...
@@ -116,24 +116,110 @@ struct IndexComponent {
...
@@ -116,24 +116,110 @@ struct IndexComponent {


## onLayout
## onLayout
<sup>9+</sup>
onLayout?(children: Array
<LayoutChild>
, constraint:
[
ConstraintSizeOptions
](
../reference/arkui-ts/ts-types.md#constraintsizeoptions
)
): void
onLayout?(children: Array
\<
LayoutChild
\>
, constraint: ConstraintSizeOptions
): void
框架会在自定义组件布局时,将该自定义组件的子节点信息和自身的尺寸范围通过onLayout传递给该自定义组件。不允许在onLayout函数中改变状态变量。
框架会在自定义组件布局时,将该自定义组件的子节点信息和自身的尺寸范围通过onLayout传递给该自定义组件。不允许在onLayout函数中改变状态变量。
## onMeasure
**参数:**
onMeasure?(children: Array
<LayoutChild>
, constraint:
[
ConstraintSizeOptions
](
../reference/arkui-ts/ts-types.md#constraintsizeoptions
)
): void
| 参数名 | 类型 | 说明 |
| ---------- | -------------------------------------------------------------------------------- | ---------------------- |
| children | Array
\<
[
LayoutChild
](
#layoutchild9
)
\>
| 子组件布局信息。 |
| constraint |
[
ConstraintSizeOptions
](
../reference/arkui-ts/ts-types.md#constraintsizeoptions
)
| 父组件constraint信息。 |
## onMeasure<sup>9+</sup>
onMeasure?(children: Array
\<
LayoutChild
\>
, constraint: ConstraintSizeOptions): void
框架会在自定义组件确定尺寸时,将该自定义组件的子节点信息和自身的尺寸范围通过onMeasure传递给该自定义组件。不允许在onMeasure函数中改变状态变量。
框架会在自定义组件确定尺寸时,将该自定义组件的子节点信息和自身的尺寸范围通过onMeasure传递给该自定义组件。不允许在onMeasure函数中改变状态变量。
## LayoutChild类型说明
**参数:**
| 参数名 | 类型 | 说明 |
| ---------- | -------------------------------------------------------------------------------- | ---------------------- |
| children | Array
\<
[
LayoutChild
](
#layoutchild9
)
\>
| 子组件布局信息。 |
| constraint |
[
ConstraintSizeOptions
](
../reference/arkui-ts/ts-types.md#constraintsizeoptions
)
| 父组件constraint信息。 |
## LayoutChild<sup>9+</sup>
子组件布局信息。
| 参数 | 参数类型 | 描述 |
| ---------- | ----------------------------------------------------------------------------------------------------------- | -------------------------------------- |
| name | string | 子组件名称。 |
| id | string | 子组件id。 |
| constraint |
[
ConstraintSizeOptions
](
../reference/arkui-ts/ts-types.md#constraintsizeoptions
)
| 子组件约束尺寸。 |
| borderInfo |
[
LayoutBorderInfo
](
#layoutborderinfo9
)
| 子组件border信息。 |
| position |
[
Position
](
../reference/arkui-ts/ts-types.md#position
)
| 子组件位置坐标。 |
| measure | (childConstraint:
[
ConstraintSizeOptions
](
../reference/arkui-ts/ts-types.md#constraintsizeoptions
)
) => void | 调用此方法对子组件的尺寸范围进行限制。 |
| layout | (LayoutInfo:
[
LayoutInfo
](
#layoutinfo9
)
) => void | 调用此方法对子组件的位置信息进行限制。 |
## LayoutBorderInfo<sup>9+</sup>
子组件border信息。
| 参数 | 参数类型 | 描述 |
| ----------- | ---------------------------------------------------------- | ---------------------------------------------- |
| borderWidth |
[
EdgeWidths
](
../reference/arkui-ts/ts-types.md#edgewidths
)
| 边框宽度类型,用于描述组件边框不同方向的宽度。 |
| margin |
[
Margin
](
../reference/arkui-ts/ts-types.md#margin
)
| 外边距类型,用于描述组件不同方向的外边距。 |
| padding |
[
Padding
](
../reference/arkui-ts/ts-types.md#padding
)
| 内边距类型,用于描述组件不同方向的内边距。 |
## LayoutInfo<sup>9+</sup>
子组件layout信息。
| 参数 | 参数类型 | 描述 |
| ---------- | -------------------------------------------------------------------------------- | ---------------- |
| position |
[
Position
](
../reference/arkui-ts/ts-types.md#position
)
| 子组件位置坐标。 |
| constraint |
[
ConstraintSizeOptions
](
../reference/arkui-ts/ts-types.md#constraintsizeoptions
)
| 子组件约束尺寸。 |
**示例3:**
```
ts
// xxx.ets
@
Entry
@
Component
struct
Index
{
build
()
{
Column
()
{
CustomLayout
()
{
ForEach
([
1
,
2
,
3
],
(
index
)
=>
{
Text
(
"
Sub
"
+
index
)
.
fontSize
(
30
)
.
borderWidth
(
2
)
})
}
}
}
}
@
Component
struct
CustomLayout
{
@
BuilderParam
builder
:
()
=>
{}
onLayout
(
children
:
Array
<
LayoutChild
>
,
constraint
:
ConstraintSizeOptions
)
{
let
pos
=
0
children
.
forEach
((
child
)
=>
{
child
.
layout
({
position
:
{
x
:
pos
,
y
:
pos
},
constraint
:
constraint
})
pos
+=
100
;
})
}
onMeasure
(
children
:
Array
<
LayoutChild
>
,
constraint
:
ConstraintSizeOptions
)
{
let
size
=
100
children
.
forEach
((
child
)
=>
{
child
.
measure
({
minHeight
:
size
,
minWidth
:
size
,
maxWidth
:
size
,
maxHeight
:
size
})
size
+=
50
})
}
build
()
{
this
.
builder
()
}
}
```
| 参数 | 参数类型 | 描述 |

| ----- | ----------- | ----------- |
| name | string | 子组件名称 |
| id | string | 子组件id |
| constraint |
[
ConstraintSizeOptions
](
../reference/arkui-ts/ts-types.md#constraintsizeoptions
)
| 子组件约束尺寸 |
| borderInfo | { borderWidth: number, margin:
[
Margin
](
../reference/arkui-ts/ts-types.md#margin
)
, padding:
[
Padding
](
../reference/arkui-ts/ts-types.md#padding
)
} | 子组件边框样式 |
| position | { x: number, y: number } | 子组件位置坐标 |
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录