在 OpenHarmony(ArkUI) 中,列表组件 是可以横向的。
常见做法有下面几种:
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、标签栏)
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%')
✅ 适合:轻量横向内容
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 开发,我可以给你更精确的示例。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。