温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

OpenHarmony列表组件能横向吗

发布时间:2026-10-10 13:16:56 来源:亿速云 阅读:85 作者:小樊 栏目:软件技术

在 OpenHarmony(ArkUI) 中,列表组件 是可以横向的。

常见做法有下面几种:


1. List 组件设置横向

通过 List 的 listDirection 属性:

List({ space: 10 }) {
  ForEach([1, 2, 3, 4, 5], (item) => {
    ListItem() {
      Text(item.toString())
        .width(80)
        .height(80)
        .backgroundColor(Color.Orange)
        .textAlign(TextAlign.Center)
    }
  })
}
.listDirection(Axis.Horizontal) // 横向
.width('100%')
.height(100)

✅ 适合:横向滚动列表(如 Banner、标签栏)


2. Scroll + Row 实现横向列表

如果只是简单横向排列:

Scroll() {
  Row({ space: 10 }) {
    ForEach([1, 2, 3, 4], (item) => {
      Text(item.toString())
        .width(80)
        .height(80)
        .backgroundColor(Color.Blue)
    })
  }
}
.scrollable(ScrollDirection.Horizontal)
.width('100%')

✅ 适合:轻量横向内容


3. Grid 横向(多行横向)

Grid() {
  ForEach([1,2,3,4,5,6], (item) => {
    GridItem() {
      Text(item.toString())
    }
  })
}
.columnsTemplate('1fr 1fr')
.scrollDirection(Axis.Horizontal)

总结

组件 是否支持横向 场景
List ✅ 标准横向列表
Scroll + Row ✅ 简单横向
Grid ✅ 横向网格

如果你用的是 OpenHarmony 哪个版本(API 9 / 10 / 11) 或 ArkTS / JS 开发,我可以给你更精确的示例。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI
助
手