【鸿蒙学习笔记】位置设置・position・绝对定位

官方文档:位置设置

position:绝对定位,确定子组件相对父组件的位置。

正→

@Entry
@Component
struct Loc_position {
  @State message: string = 'Hello World';

  build() {
    Column() {
      Column({ space: 20 }) {
        Row() {
          Text('1').size({ width: '30%', height: '50' }).backgroundColor(Color.Red)
          Text('2').size({ width: '45%', height: '50' }).backgroundColor(Color.Gray)
          Text('3').size({ width: '50', height: '30' }).backgroundColor(Color.Orange)
            .position({ x: 0, y: 0 }) // 坐标(0,0)
          Text('4').size({ width: '60%', height: '30' }).backgroundColor(Color.Yellow)
            .position({ x: 50, y: 30 }) // 坐标(50,30)
          Text('5').size({ width: '20', height: '20' }).backgroundColor(Color.Red)
            .position({ x: -20, y: -20 }) // 坐标(-20,-30)
          Text('6').size({ width: '50%', height: '50' }).backgroundColor(Color.Pink)
            .position({ x: '50%', y: '70%' }) // 坐标
        }.width('80%').height(200).border({ width: 1, style: BorderStyle.Dashed })
      }.width('100%').margin({ top: 30 })
    }.width('100%')
  }
}

在这里插入图片描述

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-14 16:30:05       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-14 16:30:05       71 阅读
  3. 在Django里面运行非项目文件

    2024-07-14 16:30:05       58 阅读
  4. Python语言-面向对象

    2024-07-14 16:30:05       69 阅读

热门阅读

  1. 大厂急招C++,有一个HC

    2024-07-14 16:30:05       19 阅读
  2. Docker:容器内服务访问宿主机中的MySql服务

    2024-07-14 16:30:05       21 阅读
  3. VsCode 使用 Tips

    2024-07-14 16:30:05       18 阅读
  4. 如何安装aab文件

    2024-07-14 16:30:05       19 阅读
  5. wordpress制作主题步骤

    2024-07-14 16:30:05       20 阅读
  6. UDP怎么实现可靠传输

    2024-07-14 16:30:05       27 阅读
  7. Unity3D开发之传送带实现

    2024-07-14 16:30:05       24 阅读
  8. Python:Scrapyd设置服务器账号密码basic authentication

    2024-07-14 16:30:05       23 阅读
  9. Python爬虫-爬取三国演义文本数据-bs4

    2024-07-14 16:30:05       23 阅读
  10. CSS 单位中 px、em 和 rem 的区别?

    2024-07-14 16:30:05       20 阅读
  11. LeetCode 第406场周赛个人题解

    2024-07-14 16:30:05       17 阅读
  12. 刷题2路2线

    2024-07-14 16:30:05       19 阅读