【鸿蒙学习笔记】位置设置

官方文档:位置设置

目录标题

align:子元素的对齐方式

cpp 复制代码
Stack() {Text('TopStart')}.width('90%').height(50).backgroundColor(0xFFE4C4).align(Alignment.TopStart)
Stack() {Text('Top')}.width('90%').height(50).backgroundColor(0xFFE4C4).align(Alignment.Top)
Stack() {Text('TopEnd')}.width('90%').height(50).backgroundColor(0xFFE4C4).align(Alignment.TopEnd)
Stack() {Text('Start')}.width('90%').height(50).backgroundColor(0xFFE4C4).align(Alignment.Start)
Stack() {Text('Center')}.width('90%').height(50).backgroundColor(0xFFE4C4).align(Alignment.Center)
Stack() {Text('End')}.width('90%').height(50).backgroundColor(0xFFE4C4).align(Alignment.End)
Stack() {Text('BottomStart')}.width('90%').height(50).backgroundColor(0xFFE4C4).align(Alignment.BottomStart)
Stack() {Text('Bottom')}.width('90%').height(50).backgroundColor(0xFFE4C4).align(Alignment.Bottom)
Stack() {Text('BottomEnd')}.width('90%').height(50).backgroundColor(0xFFE4C4).align(Alignment.BottomEnd)

direction:官方文档没懂,看图理解吧

cpp 复制代码
Row() {
  Text('1').height(50).width('25%').fontSize(16).backgroundColor(0xF5DEB3).textAlign(TextAlign.Center)
  Text('2').height(50).width('25%').fontSize(16).backgroundColor(0xD2B48C).textAlign(TextAlign.Center)
  Text('3').height(50).width('25%').fontSize(16).backgroundColor(0xF5DEB3).textAlign(TextAlign.Center)
  Text('4').height(50).width('25%').fontSize(16).backgroundColor(0xD2B48C).textAlign(TextAlign.Center)
}.width('90%').direction(Direction.Ltr)
Row() {
  Text('1').height(50).width('25%').fontSize(16).backgroundColor(0xF5DEB3).textAlign(TextAlign.Center)
  Text('2').height(50).width('25%').fontSize(16).backgroundColor(0xD2B48C).textAlign(TextAlign.Center)
  Text('3').height(50).width('25%').fontSize(16).backgroundColor(0xF5DEB3).textAlign(TextAlign.Center)
  Text('4').height(50).width('25%').fontSize(16).backgroundColor(0xD2B48C).textAlign(TextAlign.Center)
}.width('90%').direction(Direction.Rtl)
Row() {
  Text('1').height(50).width('25%').fontSize(16).backgroundColor(0xF5DEB3).textAlign(TextAlign.Center)
  Text('2').height(50).width('25%').fontSize(16).backgroundColor(0xD2B48C).textAlign(TextAlign.Center)
  Text('3').height(50).width('25%').fontSize(16).backgroundColor(0xF5DEB3).textAlign(TextAlign.Center)
  Text('4').height(50).width('25%').fontSize(16).backgroundColor(0xD2B48C).textAlign(TextAlign.Center)
}.width('90%').direction(Direction.Auto)
相关推荐
兔子不吃草~22 分钟前
Transformer学习记录与CNN思考
学习·cnn·transformer
ZZHow102424 分钟前
Maven入门_简介、安装与配置
java·笔记·maven
高心星1 小时前
HarmonyOS 5.0应用开发——V2装饰器@local的使用
harmonyos
HarmonyOS_SDK1 小时前
【FAQ】应用A如何使用应用B内的文件?
harmonyos
与己斗其乐无穷1 小时前
C++学习记录(8)list
学习
有谁看见我的剑了?1 小时前
k8s-容器探针和生命周期回调学习
学习·容器·kubernetes
万少2 小时前
可可图片编辑 HarmonyOS(6)水印效果
前端·harmonyos
流影ng2 小时前
【HarmonyOS】MVVM与三层架构
华为·架构·harmonyos
爱笑的眼睛112 小时前
HarmonyOS Stage 模型与 ArkUI 声明式开发深度实践:构建高效稳定的应用
华为·harmonyos
鸿蒙小白龙2 小时前
鸿蒙应用之网络请求方案总结
harmonyos·鸿蒙·鸿蒙系统·open harmony