鸿蒙Next 线性布局 (Row/Column)
2025-06-27 22:41:37
116次阅读
0个评论
Column 子元素按直方向排列 Row 子元素按水平方向排列 基本概念 主轴:Row容器主轴为水平方向,Column容器主轴为垂直方向。 交叉轴:垂直于主轴方向的轴线。Row容器交叉轴为垂直方向,Column容器交叉轴为水平方向。 当不指定宽高时,自身默认宽高由子组件决定,这时设置排列方向是看不到效果的。
Column交叉轴方向即横向,只有3个参数HorizontalAlign.Start,Center,End,即子组件按左,居中,右排列,比较简单。 Row交叉轴方向即纵向,是由VerticalAlign.Top,Center,Bottom,即子组件按上,居中,下排列。 以下演示一下主轴方向的排列,也是比较常用的:FlexAlign Start 首端对齐 Center 中心对齐 End 尾部对齐 SpaceBetween 第一个元与行首对齐,最后一个元素尾对齐,相邻元素间距相同 SpaceAround 第一个元素到行首的距离和最后一个元素到行尾的距离是相邻元素之间距离的一半 SpaceEvenly 相邻元素之间的距离、第一个元素与行首的间距、最后一个元素到行尾的间距都完全一样
@Entry
@Component
struct test{
build() {
Column({space:'40'}){
Row(){
Column(){
Text('1').height(90).width('100%').backgroundColor(0xF5DEB3)
Text('2').width('100%').backgroundColor(0xF5DEB3)
Text('3').width('100%').backgroundColor(0xF5DEB3)
}.height(360).width(50).backgroundColor(Color.Orange)
.justifyContent(FlexAlign.SpaceBetween)
.alignItems(HorizontalAlign.Start)
Column(){
Text('1').width('100%').backgroundColor(0xF5DEB3)
Text('2').height(90).width('100%').backgroundColor(0xF5DEB3)
Text('3').width('100%').backgroundColor(0xF5DEB3)
}.height(360).width(50).backgroundColor(Color.Blue)
.justifyContent(FlexAlign.SpaceAround)
Column(){
Text('1').width('100%').backgroundColor(0xF5DEB3)
Text('2').width('100%').backgroundColor(0xF5DEB3)
Text('3').height(90).width('100%').backgroundColor(0xF5DEB3)
}.height(360).width(50).backgroundColor(Color.Green)
.justifyContent(FlexAlign.SpaceEvenly)
}.width('100%').alignItems(VerticalAlign.Center).justifyContent(FlexAlign.SpaceEvenly)
//当我们需要在一行首尾增加一个布局时,除了使用RelativeContainer相对布局之外,还可以使用这种方式,利用SpaceBetween首尾排列,然后再设置尾部元素距离右边距,即可实现
Row(){
Column(){}.height(40).width(100).backgroundColor(Color.Green)
Column(){}.height(40).width(50).backgroundColor(Color.Brown).margin({right:50})
}.width('100%').justifyContent(FlexAlign.SpaceBetween)
}.width('100%').backgroundColor(Color.Gray)
}
}
00
- 0回答
- 0粉丝
- 0关注
相关话题
- HarmonyOS Next-布局之线性布局(Row/Column)
- HarmonyOS开发:深入解析Column和Row布局的对齐方式与间距设置
- 33. [HarmonyOS NEXT Row案例一(下)] 深入理解Row组件与按钮组布局技巧
- 16.[HarmonyOS NEXT Column案例一(上)] 使用Column组件构建垂直表单布局的基础指南
- 28.[HarmonyOS NEXT Column案例七(上)] 多层嵌套布局:打造结构清晰的详情页面
- 20.[HarmonyOS NEXT Column案例三(上)] 垂直对齐与弹性空间布局设计指南
- 37.[HarmonyOS NEXT Row案例五] 构建智能聊天气泡:Row组件的reverse属性妙用
- 32.[HarmonyOS NEXT Row案例一(上)] 使用Row组件创建水平排列的功能按钮组
- 38.[HarmonyOS NEXT Row案例六] 打造流畅水平滚动标签列表:Row与Scroll的完美结合
- 18.[HarmonyOS NEXT Column案例二(上)] 使用Column的reverse属性构建反向时间线
- 43.[HarmonyOS NEXT Row案例十一] 构建智能分页控件:Row组件实现页码与翻页按钮的完美结合
- 29.[HarmonyOS NEXT Column案例七(下)] 弹性内容与固定底栏:详情页的高级布局技巧
- 30.[HarmonyOS NEXT Column案例八(上)] 构建现代聊天界面:层叠布局与消息列表的实现
- 25.[HarmonyOS NEXT Column案例五(下)] 精细化列表项设计:多层嵌套布局与视觉层次构建
- 24.[HarmonyOS NEXT Column案例五(上)] 构建高效复合布局:垂直列表与水平操作栏的完美结合