鸿蒙开发笔记06---列表布局

1、简介

2、代码示例

class Item{
  name : String
  image:ResourceStr
  price:number
  discount:number

  constructor(name:String,image:ResourceStr,price:number,discount:number =0) {
    this.name = name
    this.image  =image
    this.price = price
    this.discount = discount
  }
}


@Entry
@Component
struct ItemPage {
//商品数据

  private  items: Array<Item> = [

     new Item('华为Mate60',$r('app.media.phone1'),6999,500),
     new Item('华为Mate60',$r('app.media.phone1'),7999),
     new Item('华为Mate60',$r('app.media.phone1'),8999),
     new Item('华为Mate60',$r('app.media.phone1'),5999),
     new Item('华为Mate60',$r('app.media.phone1'),6569),
    new Item('华为Mate60',$r('app.media.phone1'),6569),
    new Item('华为Mate60',$r('app.media.phone1'),6569),
    new Item('华为Mate60',$r('app.media.phone1'),6569)

  ]


build(){
  Column({space:8}){
    Row(){
      Text('百亿补贴')
        .fontSize(30)
        .fontWeight(FontWeight.Bold)
        .fontColor('red')
    }
    .width('100%')
    .height(30)
    .margin({bottom:20})

    List({space:8}){
      ForEach(
        this.items,
        (item:Item )=>{
          ListItem(){
            Row({space:10}){
              Image(item.image)
                .width(100)
              Column({space:4}){
                if(item.discount){
                  Text('华为Mater40')
                    .fontSize(20)
                    .fontWeight(FontWeight.Bold)
                  Text('原价:¥'+item.price)
                    .fontColor('#ccc')
                    .fontSize(14)
                    .decoration({type:TextDecorationType.LineThrough})
                  Text('折扣价:¥'+(item.price-item.discount))
                    .fontColor('#F36')
                    .fontSize(18)
                  Text('补贴¥'+item.discount)
                    .fontColor('#F36')
                    .fontSize(18)

                }else{
                  Text('华为Mater40')
                    .fontSize(20)
                    .fontWeight(FontWeight.Bold)
                  Text('¥'+item.price)
                    .fontColor('#F36')
                    .fontSize(18)
                }

              }

            }
            .width('100%')
            .height(120)
            .backgroundColor('#FFF')
            .borderRadius(20)
            .padding(10)
          }
          }

      )
    }
    .width('100%')
    .layoutWeight(1)


  }
  .width('100%')
  .height('100%')
  .backgroundColor('#EFEFEFF')
  .padding(20)
}
}

3、效果展示

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值