网站首页 > 技术教程 正文
Column 是一个沿垂直方向布局的容器。
例如:
@Entry
@Component
export struct Index {
build() {
Column() {
Text('1')
.width(100)
.height(50)
.backgroundColor(Color.Pink)
Text('2')
.width(100)
.height(50)
.backgroundColor(Color.Pink)
Text('3')
.width(100)
.height(50)
.backgroundColor(Color.Pink)
}
.width('100%')
.height('100%')
}
}
运行结果:
然后我们看到几个子组件挨在了一起。
主轴排列方式
如何把它们的分开呢?
使用 Column 的 justifyContent 属性可以指定子元素的排序方式。
Start | 元素在主轴方向首端对齐,第一个元素与行首对齐,同时后续的元素与前一个对齐。 |
Center | 元素在主轴方向中心对齐,第一个元素与行首的距离与最后一个元素与行尾距离相同。 |
End | 元素在主轴方向尾部对齐,最后一个元素与行尾对齐,其他元素与后一个对齐。 |
SpaceBetween | Flex主轴方向均匀分配弹性元素,相邻元素之间距离相同。第一个元素与行首对齐,最后一个元素与行尾对齐。 |
SpaceAround | Flex主轴方向均匀分配弹性元素,相邻元素之间距离相同。第一个元素到行首的距离和最后一个元素到行尾的距离是相邻元素之间距离的一半。 |
SpaceEvenly | Flex主轴方向均匀分配弹性元素,相邻元素之间的距离、第一个元素与行首的间距、最后一个元素到行尾的间距都完全一样。 |
Start
元素在主轴方向首端对齐,第一个元素与行首对齐,同时后续的元素与前一个对齐。
示例:
Column() {
Text('1')
.width(100)
.height(50)
.backgroundColor(Color.Pink)
Text('2')
.width(100)
.height(50)
.backgroundColor(Color.Pink)
Text('3')
.width(100)
.height(50)
.backgroundColor(Color.Pink)
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.SpaceBetween)
运行结果:
默认的排列方式。
Center
元素在主轴方向中心对齐,第一个元素与行首的距离与最后一个元素与行尾距离相同。
接下来,将 justifyContent 的值设为 FlexAlign.Center。
运行结果:
End
元素在主轴方向尾部对齐,最后一个元素与行尾对齐,其他元素与后一个对齐。
接下来,将 justifyContent 的值设为 FlexAlign.End。
运行结果:
SpaceBetween
Flex主轴方向均匀分配弹性元素,相邻元素之间距离相同。第一个元素与行首对齐,最后一个元素与行尾对齐。
接下来,将 justifyContent 的值设为 FlexAlign.SpaceBetween。
运行结果:
SpaceAround
Flex主轴方向均匀分配弹性元素,相邻元素之间距离相同。第一个元素到行首的距离和最后一个元素到行尾的距离是相邻元素之间距离的一半。
接下来,将 justifyContent 的值设为 FlexAlign.SpaceAround。
运行结果:
SpaceEvenly
Flex主轴方向均匀分配弹性元素,相邻元素之间的距离、第一个元素与行首的间距、最后一个元素到行尾的间距都完全一样。
将 justifyContent 的值设为 FlexAlign.SpaceEvenly。
运行结果:
交叉轴排列方式
交叉轴方向上通过 alignItems 属性来设置。
Start | 按照语言方向起始端对齐。 |
Center | 居中对齐,默认对齐方式。 |
End | 按照语言方向末端对齐。 |
Start
按照语言方向起始端对齐。
示例:
Column() {
Text('1')
.width(100)
.height(50)
.backgroundColor(Color.Pink)
Text('2')
.width(100)
.height(50)
.backgroundColor(Color.Pink)
Text('3')
.width(100)
.height(50)
.backgroundColor(Color.Pink)
}
.width('100%')
.height('100%')
.justifyContent(FlexAlign.Start)
.alignItems(HorizontalAlign.Start)
运行结果:
Center
居中对齐,默认对齐方式。
将 alignItems 的值设为 HorizontalAlign.Center。
运行结果:
默认的对齐方式。
End
按照语言方向末端对齐。
将 alignItems 的值设为 HorizontalAlign.End。
运行结果:
space
除了设置主轴和交叉轴两个方向上的排列方式以外,我们还可以通过 space 参数来分割子组件。
例如,将 space 设置为 20vp,里面的子元素默认间隔为 20vp:
Column({ space: 20 }) {
Text('1')
.width(100)
.height(50)
.backgroundColor(Color.Pink)
Text('2')
.width(100)
.height(50)
.backgroundColor(Color.Pink)
Text('3')
.width(100)
.height(50)
.backgroundColor(Color.Pink)
}
.width('100%')
.height('100%')
运行结果:
至此,Column 的内容就介绍完了。
猜你喜欢
- 2024-11-08 区间统计的那些事(frequency函数的运用)
- 2024-11-08 Excel一列数据转多行多列,这4条函数公式可以学起来
- 2024-11-08 excel函数技巧:reduce+column+expand平分数据重构表格
- 2024-11-08 excel函数技巧:reduce+row+column将表格转换成以姓名为主的表格
- 2024-11-08 Vlookup Column公式组合,强强联手,你会么?
- 2024-11-08 Excel中将一列分成多列多行的操作技巧,同事分分钟完成了
- 2024-11-08 偷偷学会这个小众高能函数,我再也没有加过班
- 2024-11-08 「Flutter应用开发教程」-基本布局组件Row和Column
- 2024-11-08 Excel里面有趣的数字(有数字的表格)
- 2024-11-08 有声书音频地址合集(有声书网站比较有名)
你 发表评论:
欢迎- 最近发表
-
- Win11学院:如何在Windows 11上使用WSL安装Ubuntu
- linux移植(Linux移植freemodbus)
- 独家解读:Win10预览版9879为何无法识别硬盘
- 基于Linux系统的本地Yum源搭建与配置(ISO方式、RPM方式)
- Docker镜像瘦身(docker 减小镜像大小)
- 在linux上安装ollama(linux安装locale)
- 渗透测试系统Kali推出Docker镜像(kali linux渗透测试技术详解pdf)
- Linux环境中部署Harbor私有镜像仓库
- linux之间传文件命令之Rsync傻瓜式教程
- 解决ollama在linux中安装或升级时,通过国内镜像缩短安装时长
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)