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

鸿蒙开发-布局

 4.1布局-grid布局

 // Grid布局的基本使用: 规则的行列布局中非常常见, 3行4列
   
 Grid() {
      ForEach([1,2,3,4,5,6,7,8,9,10,11,12], () => {
        GridItem() {
          Column() {

          }
          .width('100%')
          .height('100%')
          .backgroundColor(Color.Green)
          .border({ width: 1 })
        }
      })
    }
    .columnsTemplate('1fr 1fr 1fr 1fr')
    .rowsTemplate('1fr 1fr 1fr')
    .columnsGap(5)
    .rowsGap(5)
    .width('100%')
    .height(500)
    .backgroundColor(Color.Pink)

4.2 Flex布局

    // Flex默认主轴水平往右,交叉轴垂直往下 → Row
    // 1. 主轴方向
    //    direction: FlexDirection.Row / Column
    // 2. 主轴对齐方式
    //    justifyContent: FlexAlign.SpaceAround
    // 3. 交叉轴对齐方式
    //    alignItems: ItemAlign.Stretch / Start / Center / End
    // 单行或者单列的情况,优先还是使用线性布局(本质基于Flex设计的,且还做了性能优化)

    // Flex布局:伸缩布局。当子盒子的总和溢出父盒子,默认进行压缩显示。
    // 4. 换行 wrap
    //    FlexWrap.Wrap 换行
    //    FlexWrap.NoWrap 不换行
    Flex({
      direction: FlexDirection.Column,
      justifyContent: FlexAlign.SpaceBetween,
      alignItems: ItemAlign.Start,
      wrap: FlexWrap.Wrap
    }) {
      Text()
        .width(80).height(80)
        .backgroundColor(Color.Pink)
        .border({ width: 1, color: Color.Blue })
      Text()
        .width(80).height(80)
        .backgroundColor(Color.Pink)
        .border({ width: 1, color: Color.Blue })
      Text()
        .width(80).height(80)
        .backgroundColor(Color.Pink)
        .border({ width: 1, color: Color.Blue })
    }
    .width('100%')
    .height(600)
    .backgroundColor('#5f9a5c')

 4.3 层叠布局

    // 层叠布局
    Stack({
      alignContent: Alignment.Bottom
    }) {
      Text('大儿子')
        .width(250)
        .height(250)
        .backgroundColor(Color.Green)
        .zIndex(3)
      Text('二儿子')
        .width(150)
        .height(150)
        .backgroundColor(Color.Orange)
        .zIndex(4)
      Text('三儿子')
        .width(50)
        .height(50)
        .backgroundColor(Color.Yellow)
        .zIndex(5)
    }
    .width(300)
    .height(600)
    .backgroundColor(Color.Pink)

相关文章:

  • CTF-SQL注入
  • Go:接口
  • 大风频繁,疾风气象大模型竞速:AI如何提前10天预测极端天气?
  • Spark SQL
  • C++ 用红黑树封装map/set
  • PD-1 功能性抗体知多少
  • 静态代码扫描概述
  • 【数据标准】数据标准化-现状分析及评估
  • 信息系统项目管理工程师备考计算类真题讲解二
  • 【补题】Codeforces Round 857 (Div. 1) A. The Very Beautiful Blanket
  • 如何开发一套场外个股期权交易系统?个股期权交易软件包含:询价,报价,交易,持仓,行权,账户盈亏统计等
  • 金融行业 AI 报告自动化:Word+PPT 双引擎生成方案
  • 【指纹浏览器系列-chromium编译】
  • OpenCV图像处理进阶教程:几何变换与频域分析全解析
  • CExercise_10_5指针高级_1 1.按照字符串的长度,从长到短排序 2.先按照字符串的长度从短到长排序,长度一致的字符串按照字典顺序排序。
  • 《鸿蒙软总线:基于UDP的数据传输奥秘与优势》
  • Redis持久化策略
  • Java 多线程编程之原子类 AtomicInteger(构造方法、常用方法、高级操作方法)
  • x265 编码参数 maxNumReferences 详细解析与实验
  • 散户使用算法交易怎么做?
  • 龚桢梽任广东省发展和改革委员会副主任
  • 霸王茶姬成美股“中国茶饮第一股”:首日涨近16%,市值60亿美元
  • 习近平会见柬埔寨太后莫尼列
  • ​COP30候任主席答澎湃:走自己的务实道路,不依赖发达国家“标准答案”
  • 工信部:汽车生产企业要充分开展组合驾驶辅助测试验证,不得夸大和虚假宣传
  • 五连冠创造历史!居文君击败谭中怡完成国象棋后战卫冕