Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
2fd3a96f
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
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看板
提交
2fd3a96f
编写于
10月 21, 2022
作者:
S
sienna1128
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update docs
Signed-off-by:
N
sienna1128
<
lixiaoyan45@huawei.com
>
上级
6a642a65
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
74 addition
and
74 deletion
+74
-74
zh-cn/application-dev/ui/ui-ts-layout-flex.md
zh-cn/application-dev/ui/ui-ts-layout-flex.md
+72
-72
zh-cn/application-dev/ui/ui-ts-layout-grid-container-new.md
zh-cn/application-dev/ui/ui-ts-layout-grid-container-new.md
+2
-2
未找到文件。
zh-cn/application-dev/ui/ui-ts-layout-flex.md
浏览文件 @
2fd3a96f
...
...
@@ -467,87 +467,87 @@ Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center }) { //容器
### 弹性布局的自适应拉伸
在弹性布局父组件尺寸不够大的时候,通过子组件的下面几个属性设置其再父容器的占比,达到自适应布局能力。
1.
flexBasis: 设置子组件在父容器主轴方向上的基准尺寸。如果设置了该值,则子项占用的空间为设置的值;如果没设置或者为auto,那子项的空间为width/height的值。
```
ts
Flex
()
{
Text
(
'
flexBasis("auto")
'
)
.
flexBasis
(
'
auto
'
)
// 未设置width以及flexBasis值为auto,内容自身宽松
.
height
(
100
)
.
backgroundColor
(
0xF5DEB3
)
Text
(
'
flexBasis("auto")
'
+
'
width("40%")
'
)
.
width
(
'
40%
'
)
.
flexBasis
(
'
auto
'
)
//设置width以及flexBasis值auto,使用width的值
.
height
(
100
)
.
backgroundColor
(
0xD2B48C
)
Text
(
'
flexBasis(100)
'
)
// 未设置width以及flexBasis值为100,宽度为100vp
.
flexBasis
(
100
)
.
height
(
100
)
.
backgroundColor
(
0xF5DEB3
)
Text
(
'
flexBasis(100)
'
)
.
flexBasis
(
100
)
.
width
(
200
)
// flexBasis值为100,覆盖width的设置值,宽度为100vp
.
height
(
100
)
.
backgroundColor
(
0xD2B48C
)
}.
width
(
'
90%
'
).
height
(
120
).
padding
(
10
).
backgroundColor
(
0xAFEEEE
)
```

2.
flexGrow: 设置父容器的剩余空间分配给此属性所在组件的比例。用于"瓜分"父组件的剩余空间。
```
ts
Flex
()
{
Text
(
'
flexGrow(1)
'
)
.
flexGrow
(
2
)
.
width
(
100
)
.
height
(
100
)
.
backgroundColor
(
0xF5DEB3
)
-
flexBasis: 设置子组件在父容器主轴方向上的基准尺寸。如果设置了该值,则子项占用的空间为设置的值;如果没设置或者为auto,那子项的空间为width/height的值。
Text
(
'
flexGrow(3)
'
)
.
flexGrow
(
2
)
.
width
(
100
)
.
height
(
100
)
.
backgroundColor
(
0xD2B48C
)
```
ts
Flex
()
{
Text
(
'
flexBasis("auto")
'
)
.
flexBasis
(
'
auto
'
)
// 未设置width以及flexBasis值为auto,内容自身宽松
.
height
(
100
)
.
backgroundColor
(
0xF5DEB3
)
Text
(
'
flexBasis("auto")
'
+
'
width("40%")
'
)
.
width
(
'
40%
'
)
.
flexBasis
(
'
auto
'
)
//设置width以及flexBasis值auto,使用width的值
.
height
(
100
)
.
backgroundColor
(
0xD2B48C
)
Text
(
'
flexBasis(100)
'
)
// 未设置width以及flexBasis值为100,宽度为100vp
.
flexBasis
(
100
)
.
height
(
100
)
.
backgroundColor
(
0xF5DEB3
)
Text
(
'
flexBasis(100)
'
)
.
flexBasis
(
100
)
.
width
(
200
)
// flexBasis值为100,覆盖width的设置值,宽度为100vp
.
height
(
100
)
.
backgroundColor
(
0xD2B48C
)
}.
width
(
'
90%
'
).
height
(
120
).
padding
(
10
).
backgroundColor
(
0xAFEEEE
)
```
!
[](
figures/flexbasis.png
)
Text
(
'
no flexGrow
'
)
.
width
(
100
)
.
height
(
100
)
.
backgroundColor
(
0xF5DEB3
)
}.
width
(
400
).
height
(
120
).
padding
(
10
).
backgroundColor
(
0xAFEEEE
)
```
-
flexGrow: 设置父容器的剩余空间分配给此属性所在组件的比例。用于"瓜分"父组件的剩余空间。

```
ts
Flex
()
{
Text
(
'
flexGrow(1)
'
)
.
flexGrow
(
2
)
.
width
(
100
)
.
height
(
100
)
.
backgroundColor
(
0xF5DEB3
)
Text
(
'
flexGrow(3)
'
)
.
flexGrow
(
2
)
.
width
(
100
)
.
height
(
100
)
.
backgroundColor
(
0xD2B48C
)
Text
(
'
no flexGrow
'
)
.
width
(
100
)
.
height
(
100
)
.
backgroundColor
(
0xF5DEB3
)
}.
width
(
400
).
height
(
120
).
padding
(
10
).
backgroundColor
(
0xAFEEEE
)
```
!
[](
figures/flexgrow.png
)
上图中,父容器宽度400vp, 三个子组件原始宽度为100vp,综合300vp,剩余空间100vp根据flexGrow值的占比分配给子组件,未设置flexGrow的子组件不参与“瓜分”。
第一个元素以及第二个元素以2:3分配剩下的100vp。第一个元素为100vp+100vp
*2/5=140vp,第二个元素为100vp+100vp*
3/5=160vp。
3.
flexShrink: 当父容器空间不足时,子组件的压缩比例。
-
flexShrink: 当父容器空间不足时,子组件的压缩比例。
```
ts
Flex
({
direction
:
FlexDirection
.
Row
})
{
Text
(
'
flexShrink(3)
'
)
.
flexShrink
(
3
)
.
width
(
200
)
.
height
(
100
)
.
backgroundColor
(
0xF5DEB3
)
```
ts
Flex
({
direction
:
FlexDirection
.
Row
})
{
Text
(
'
flexShrink(3)
'
)
.
flexShrink
(
3
)
.
width
(
200
)
.
height
(
100
)
.
backgroundColor
(
0xF5DEB3
)
Text
(
'
no flexShrink
'
)
.
width
(
200
)
.
height
(
100
)
.
backgroundColor
(
0xD2B48C
)
Text
(
'
no flexShrink
'
)
.
width
(
200
)
.
height
(
100
)
.
backgroundColor
(
0xD2B48C
)
Text
(
'
flexShrink(2)
'
)
.
flexShrink
(
2
)
.
width
(
200
)
.
height
(
100
)
.
backgroundColor
(
0xF5DEB3
)
}.
width
(
400
).
height
(
120
).
padding
(
10
).
backgroundColor
(
0xAFEEEE
)
```

Text
(
'
flexShrink(2)
'
)
.
flexShrink
(
2
)
.
width
(
200
)
.
height
(
100
)
.
backgroundColor
(
0xF5DEB3
)
}.
width
(
400
).
height
(
120
).
padding
(
10
).
backgroundColor
(
0xAFEEEE
)
```
!
[](
figures/flexshrink.png
)
## 场景示例
...
...
zh-cn/application-dev/ui/ui-ts-layout-grid-container-new.md
浏览文件 @
2fd3a96f
# 栅格布局
栅格组件
[
GridRow
](
../reference/arkui-ts/ts-container-gridrow.md
)
和
[
GridCol
](
../reference/arkui-ts/ts-container-gridcol.md
)
相对于
[
GridContainer
](
../reference/arkui-ts/ts-container-gridcontainer.md
)
提供了更灵活、更全面的栅格系统实现方案。
其中GridRow为栅格容器组件,仅可以和栅格子组件(GridCol)
在栅格布局场景中使用。
相对于
[
GridContainer
](
../reference/arkui-ts/ts-container-gridcontainer.md
)
提供了更灵活、更全面的栅格系统实现方案。
GridRow为栅格容器组件,只与栅格子组件GridCol
在栅格布局场景中使用。
## 栅格容器GridRow
...
...
@@ -14,7 +14,7 @@
-
breakpoints:以设备宽度为基准,将应用宽度分成了几个不同的区间,即不同的断点。开发者可根据需要在不同的区间下实现不同的页面布局效果。
首
次通过设置断点位置,得到一系列断点区间;其次,借助栅格组件能力监听应用窗口大小的变化,判断应用当前处于哪个断点区间,进而可以调整应用的布局,实现栅格
布局。
首
先通过设置断点,得到一系列断点区间;然后,借助栅格组件能力监听应用窗口大小的变化,判断应用当前处于哪个断点区间,最后调整应用的
布局。
### 栅格系统断点
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录