当前位置: 首页 > article >正文

【鸿蒙应用开发】常见的容器组件:ColumnSplit、RowSplit和Flex

上一章已经了解了Column和Row的一些属性,以下是几个案例:

设置子组件水平方向的间距为:5

@Entry
@Preview
@Component
struct Index {
  @State message: string = 'Hello 鸿蒙';
  controller: webview.WebviewController = new webview.WebviewController();

  build() {
    Column() {
      Row({ space: 5 }) {
        Row()
          .width("30%")
          .height(50)
          .backgroundColor("red")
        Row()
          .width("30%")
          .height(50)
          .backgroundColor("blue")
      }
      .width("90%")
      .height('100%')
      .border({ width: 1 })

    }
    .height('100%')
    .width('100%')
  }
}

效果如图所示:
在这里插入图片描述

设置子元素垂直方向上的对齐方式:

@Entry
@Preview
@Component
struct Index {
  @State message: string = 'Hello 鸿蒙';
  controller: webview.WebviewController = new webview.WebviewController();

  build() {
    Column() {
      Row({ space: 5 }) {
        Row()
          .width("30%")
          .height(50)
          .backgroundColor("red")
        Row()
          .width("30%")
          .height(50)
          .backgroundColor("blue")
      }
      .width("90%")
      .height('100%')
      .border({ width: 1 })
      .alignItems(VerticalAlign.Center)
    }
    .height('100%')
    .width('100%')
  }
}

效果如图所示:

在这里插入图片描述
其他的对齐方式,选择对应的属性即可。

ColumnSplit和RowSplit

ColumnSplit和RowSplit是在每一个子组件之间插入一条分隔线,ColumnSplit是横向分隔线,RowSplit是纵向的分隔线。

RowSplit使用方法如下:

@Entry
@Preview
@Component
struct Index {
  @State message: string = 'Hello 鸿蒙';
  controller: webview.WebviewController = new webview.WebviewController();

  build() {
    Column() {
      RowSplit(){
        Text("1")
          .width(100)
          .height(30)
          .backgroundColor(0xF5DEB3)
        Text("1")
          .width(100)
          .height(30)
          .backgroundColor(0xF5DEB3)
        Text("1")
          .width(100)
          .height(30)
          .backgroundColor(0xF5DEB3)
      }
      .resizeable(true) // 是否可拖动
      .width("90%").height(400)
    }
    .height('100%')
    .width('100%')
  }
}

效果如图:在这里插入图片描述
ColumnSplit的用法也是类似的。

Flex

Flex组件是以弹性方式布局子元素,标准的Flex布局容器包含以下参数:

  • direction:子组件在 flex 容器上排列的方向,也就是主轴方向。
  • wrap:Flex 容器以单行/列 还是多行/列排列。
  • justifyContent:子组件在 Flex 容器主轴上的对齐格式
  • alignItems:子组件在 Flex 容器交叉轴的对齐方式
  • alignContent:交叉轴上有额外空间的时候,多行内容的对齐方式,只有在 wrap 为Wrap或WrapReverse时生效。

比如:

      Flex({direction:FlexDirection.Row}){
        Text("1").width(100).height(40).backgroundColor(0xF5DEB3)
        Text("1").width(100).height(40).backgroundColor(0xF5DEB3)
        Text("1").width(100).height(40).backgroundColor(0xF5DEB3)
        Text("1").width(100).height(40).backgroundColor(0xF5DEB3)
      }

效果如图:在这里插入图片描述

今天先总结ColumnSplit、RowSplit和Flex三个组件


http://www.kler.cn/a/299436.html

相关文章:

  • JavaScript原型链与继承:优化与扩展的深度探索
  • 剑指offer 数组 持续更新中...
  • 数据结构-Stack和栈
  • 商密测评题库详解:商用密码应用安全性评估从业人员考核题库详细解析(8)
  • C# 9.0记录类型:解锁开发效率的魔法密码
  • WordPress使用(1)
  • Mac M1 配置go环境
  • 用亚马逊云科技Graviton高性能/低耗能处理器构建AI向量数据库(下篇)
  • 【C++ 面试题】构造函数和析构函数你了解多少呢?
  • 深入探索Java中的分布式锁服务与Zookeeper集成
  • 【FastAPI】文件响应方法StreamingResponse和 FileResponse的用法和场景
  • 在IDEA中如何创建web项目?——不使用Archetype
  • DC-DC恒频电流模式3A降压转换器,小体积封装
  • Android生成C++ AIDL
  • FastAPI 深入学习:利用__call__方法实现动态依赖项
  • 【腾讯云】AI驱动的数据库TDSQL-C如何是从0到1体验电商可视化分析小助手得统计功能,一句话就能输出目标统计图
  • 自己看---华为od--构成正方形的数量
  • 神经网络的可解释性理论及工具
  • timedatectl /date /hwclock 命令
  • Rust使用之【宏】
  • Vue(7)——工程化开发
  • 基于SpringBoot+Vue的学生成绩管理系统
  • [苍穹外卖]-04菜品管理接口开发
  • Node.js入门与生态全解析:包管理与构建工具详解
  • 从代码层面说算子链断链的方式
  • 【OJ刷题】双指针问题