HarmonyOS学习ArkUI之线性布局 (Row/Column)

线性布局是其他布局的基础,其子元素在线性方向上(水平方向和垂直方向)依次排列.

  • Column(列,垂直布局)
  • Row(行,水平布局)

属性:

  • space 间隔
  • Blank 空白填充
  • layoutWeight(权重)等分
scss 复制代码
//滑动
Scroll(this.scroller) {
//间隔
Column({ space: "35" }) {
  Text("11").width("100%").backgroundColor("#333333").fontColor("#fff").textAlign(TextAlign.Center)
  Row() {
    Text("水平").width("100").backgroundColor("#333333").fontColor("#fff").textAlign(TextAlign.Center)
    //空白填充
    Blank()
    Toggle({ type: ToggleType.Checkbox, isOn: true })
  }.width("100%")

  Row({ space: "35" }) {
    Row() {
      Text("等分")
        .backgroundColor("#333333")
        .fontColor("#fff")
        .textAlign(TextAlign.Center)
        .align(Alignment.Center)
        .width("100%")
        .height("100")
    }
    //权重
    .layoutWeight(1).backgroundColor(Color.Blue)

    Row() {
      Text("等分")
        .backgroundColor("#333333")
        .fontColor("#fff")
        .textAlign(TextAlign.Center)
        .align(Alignment.Center)
        .width("100%")
        .height("100")
    }.layoutWeight(1).backgroundColor(Color.Blue)

    Row() {
      Text("等分")
        .backgroundColor("#333333")
        .fontColor("#fff")
        .textAlign(TextAlign.Center)
        .align(Alignment.Center)
        .width("100%")
        .height("100")
    }.layoutWeight(1).backgroundColor(Color.Blue)
  }.width("100%")

  Text("11").width("100%").backgroundColor("#333333").fontColor("#fff").textAlign(TextAlign.Center)
  Text("11").width("100%").backgroundColor("#333333").fontColor("#fff").textAlign(TextAlign.Center)
  Text("11").width("100%").backgroundColor("#333333").fontColor("#fff").textAlign(TextAlign.Center)
  Text("11").width("100%").backgroundColor("#333333").fontColor("#fff").textAlign(TextAlign.Center)
  Text("11").width("100%").backgroundColor("#333333").fontColor("#fff").textAlign(TextAlign.Center)
  Text("11").width("100%").backgroundColor("#333333").fontColor("#fff").textAlign(TextAlign.Center)
  Text("11").width("100%").backgroundColor("#333333").fontColor("#fff").textAlign(TextAlign.Center)
  Text("11").width("100%").backgroundColor("#333333").fontColor("#fff").textAlign(TextAlign.Center)
  Text("11").width("100%").backgroundColor("#333333").fontColor("#fff").textAlign(TextAlign.Center)
  Text("11").width("100%").backgroundColor("#333333").fontColor("#fff").textAlign(TextAlign.Center)
  Text("11").width("100%").backgroundColor("#333333").fontColor("#fff").textAlign(TextAlign.Center)
  Text("11").width("100%").backgroundColor("#333333").fontColor("#fff").textAlign(TextAlign.Center)
  Text("11").width("100%").backgroundColor("#333333").fontColor("#fff").textAlign(TextAlign.Center)

}.margin({right:20})
}
.backgroundColor(0xDCDCDC)
.scrollable(ScrollDirection.Vertical) // 滚动方向为垂直方向
.scrollBar(BarState.On) // 滚动条常驻显示
.scrollBarColor(Color.Gray) // 滚动条颜色
.scrollBarWidth(10) // 滚动条宽度
.edgeEffect(EdgeEffect.Spring) // 滚动到边沿后回弹
.width("100%").height("100%")
.padding({
  top: px2vp(ScreenUtil.getInstance().getTopRectHeight()),
  bottom: px2vp(ScreenUtil.getInstance().getBottomRectHeight())
})

总结

  • Row 水平布局
  • Colum 垂直布局
  • space 间隔
  • Blank 空布局填充 (自适应拉伸效果)
  • layoutWeight 权重效果
  • Scroll 滑动控件
相关推荐
爱笑的眼睛117 小时前
HarmonyOS 应用开发:深入探索截屏与录屏API的创新实践
华为·harmonyos
爱笑的眼睛117 小时前
深入探讨HarmonyOS中ListItem的滑动操作实现与优化
华为·harmonyos
爱笑的眼睛1111 小时前
可可图片编辑 HarmonyOS 上架应用分享
华为·harmonyos
东林知识库11 小时前
HarmonyOS 6 开发者预览版 Beta 招募
华为·harmonyos
无尽星海max11 小时前
用虚拟机体验纯血鸿蒙所有机型!
华为·harmonyos
I'mAlex11 小时前
0 基础入门鸿蒙:跟着《HarmonyOS 第一课》1 周掌握应用开发核心能力
华为·harmonyos
工藤学编程11 小时前
仓颉原子操作封装:从底层原理到鸿蒙高并发实战
华为·harmonyos
User_芊芊君子11 小时前
【成长纪实】我的鸿蒙成长之路:从“小白”到独立开发,带你走进鸿蒙的世界
学习·华为·harmonyos·鸿蒙开发
●VON11 小时前
【成长纪实】三个月的鸿蒙成长之路:大学生从0开始的鸿蒙心得与体会
华为·架构·harmonyos·鸿蒙·鸿蒙系统·鸿蒙开发·成长纪实
Jinkxs11 小时前
仓颉语言性能优化指南:实测对比,让鸿蒙应用运行效率提升 40%
华为·性能优化·harmonyos