鸿蒙开发案例:健康App(6)饮食记录-记录列表

系列文章目录

鸿蒙开发案例:健康App(1)欢迎页面Ul实现

                         健康App(2)欢迎页面业务

                         健康App(3)首页Tabs

                         健康App(4)饮食记录-顶部搜索栏 

                         健康App(5)饮食记录-统计卡片

                         健康App(6)饮食记录-记录列表


前言

案例来源于黑马程序员的课程


案例介绍

饮食记录-记录列表

一、整体思路

一个卡片,内部是一个List布局,从上到下一行一行的,使用Column容器

二、实现步骤

1.分组的标题

使用Row容器,使图标,加粗文字,灰色文字在同一水平线上(左边)

(右边)

写个for循环,写个假的数组,加listitem,把Column扔进去,就有很多组样式了。

2.组内记录列表

一行里有一个图片两行文本,所以图片大些,再用个Column来写两行文本;再整个循环。

要给list加删除,先加个侧滑效果

用一个builder定义删除图标, 添加点击事件,删除元素

但现在还没实现删除功能


总结

完整代码如下:

// src/main/ets/view/record/RecordList.ets

import { CommonConstants } from '../../common/constants/CommonConstants'

@Extend(Text) function grayText() {
  .fontSize(14)
  .fontColor($r('app.color.light_gray'))
}

@Component
export default struct RecordList {
  build() {
    List({space: CommonConstants.SPACE_10}){
      ForEach([1,2,3,4,5,6], (item) => {
        ListItem() {
          Column({ space: CommonConstants.SPACE_8 }) {
            // 1.分组的标题
            Row({space: CommonConstants.SPACE_4}){
              Image($r('app.media.ic_breakfast')).width(24)
              Text('早餐').fontSize(18).fontWeight(CommonConstants.FONT_WEIGHT_700)
              Text('建议423-592千卡').grayText()
              Blank()
              Text('190').fontSize(14).fontColor($r('app.color.primary_color'))
              Text('千卡').grayText()
              Image($r('app.media.ic_public_add_norm_filled'))
                .width(20)
                .fillColor($r('app.color.primary_color'))
            }
            .width('100%')
            // 2.组内记录列表
            List(){
              ForEach([1,2], (item) => {
                ListItem(){
                  Row({space: CommonConstants.SPACE_6}){
                    Image($r('app.media.toast')).width(50)
                    Column({space: CommonConstants.SPACE_4}){
                      Text('全麦土司').fontWeight(CommonConstants.FONT_WEIGHT_500)
                      Text(`1片`).grayText()
                    }
                    Blank()
                    Text('91千卡').grayText()
                  }
                  .width('100%')
                  .padding(CommonConstants.SPACE_6)
                }.swipeAction({end: this.deleteButton.bind(this)})
              })
            }
            .width('100%')
          }
          .width('100%')
          .backgroundColor(Color.White)
          .borderRadius(CommonConstants.DEFAULT_18)
          .padding(CommonConstants.SPACE_12)
        }
      })
    }
    .width(CommonConstants.THOUSANDTH_940)
    .height('100%')
    .margin({top: 10})
  }

  @Builder deleteButton() {
    Image($r('app.media.ic_public_delete_filled'))
      .width(20)
      .height(20)
      .fillColor(Color.Red)
      .margin(5)
  }
}

记得修改

  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值