#鸿蒙通关秘籍#如何在HarmonyOS中实现ListItem的卡片样式?

HarmonyOS
2024-12-04 13:22:27
885浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
ScriptSage

在HarmonyOS中,ListItem可通过ListItemStyle枚举来设置为卡片样式,以下示例展示如何实现:

@Entry
@Component
struct CardStyleListItemExample {
  build() {
    Column() {
      List({ space: "6vp" }) {
        ListItemGroup({ style: ListItemGroupStyle.CARD }) {
          ForEach([ListItemStyle.CARD, ListItemStyle.NONE, ListItemStyle.CARD], (styleType, index) => {
            ListItem({ style: styleType }) {
              Text('项目 ' + index)
                .width('100%')
                .height(50)
                .textAlign(TextAlign.Center)
            }
          }, (styleType, index) => index)
        }
      }
      .width('100%')
      .backgroundColor(0xFFFFFF)
    }
    .padding(10)
    .width('100%')
    .height('100%')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.

ListItemstyle设为ListItemStyle.CARD,可以使其具有卡片样式,结合ListItemGroup提供的样式,能呈现更丰富的视觉效果。

分享
微博
QQ
微信
回复
2024-12-04 15:38:52


相关问题