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 滑动控件
相关推荐
HarmonyOS_SDK14 分钟前
超越常规扫码:鸿蒙扫码如何实现复杂、远距二维码的快速精准捕捉
harmonyos
在下历飞雨5 小时前
Kuikly基础之动画实战:让孤寡青蛙“活”过来
前端·ios·harmonyos
马剑威(威哥爱编程)6 小时前
【鸿蒙开发实战篇】HarmonyOS 6.0 蓝牙实现服务端和客户端通讯案例详解
华为·蓝牙·harmonyos
遇到困难睡大觉哈哈6 小时前
Harmony os——ArkTS 高性能编程实践 – 速查笔记
笔记·harmonyos·鸿蒙
平平不平凡7 小时前
Grid组件核心参数解析:控制器与布局选项详解
harmonyos
灰灰勇闯IT7 小时前
Flutter×VS Code:跨端开发的高效协作指南(2025最新配置)
笔记·flutter·harmonyos
Rene_ZHK7 小时前
Day1鸿蒙开发环境部署:从零开始的工程化配置指南
华为·harmonyos
遇到困难睡大觉哈哈8 小时前
Harmony os 网络防火墙实战:用 @ohos.net.netFirewall 给应用加一道“网闸”
网络·.net·harmonyos·鸿蒙
马剑威(威哥爱编程)8 小时前
【鸿蒙开发实战篇】如何实现高级图片滤镜
华为·harmonyos
马剑威(威哥爱编程)8 小时前
【鸿蒙开发实战篇】鸿蒙6.0图片编辑实战:PixelMap与Canvas的完美结合
华为·harmonyos