<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      鴻蒙應用開發從入門到實戰(十六):線性布局案例

      線性布局案例:商品列表

      大家好,我是潘Sir,持續分享IT技術,幫你少走彎路。《鴻蒙應用開發從入門到項目實戰》系列文章持續更新中,陸續更新AI+編程、企業級項目實戰等原創內容、歡迎關注!

      ArkUI提供了豐富的系統組件,用于制作鴻蒙原生應用APP的UI,本文通過簡單案例演示如何使用Column和Row組件實現線性布局。

      一、商品列表

      1.1 效果圖

      3折扣價列表

      相關知識:

      ? 線性布局

      ? 渲染控制:循環渲染、條件渲染

      1.2 實現代碼

      拷貝素材

      ? 將mate60.png拷貝到resources/base/media目錄

      ? 在pages/layout/linear下新建ProductListPage.ets文件

      1.2.1 先實現靜態界面

      界面分析

      0布局分析

      @Entry
      @Component
      struct ProductListPage {
        build() {
          Column({ space: 8 }) {
            // 標題
            Row() {
              Text('商品列表')
                .fontSize(30)
                .fontWeight(FontWeight.Bold)
            }
            .width('100%')
            .margin({ bottom: 20 })
      
            // 商品列表
            Row({ space: 10 }) {
              Image($r('app.media.mate60'))
                .width(100)
              Column({ space: 4 }) {
                Text('華為Mate60')
                  .fontSize(20)
                  .fontWeight(FontWeight.Bold)
                Text('¥ 6999')
                  .fontColor('#F36')
                  .fontSize(18)
              }
              .height('100%')
              .alignItems(HorizontalAlign.Start)
            }
            .width('100%')
            .backgroundColor('#FFF')
            .borderRadius(20)
            .height(120)
            .padding(10)
          }
          .width('100%')
          .height('100%')
          .backgroundColor('#EFEFEF')
          .padding(20)
        }
      }
      

      效果圖

      1靜態界面

      1.2.2 數據循環渲染

      由于列表項都相同,因此可以直接復制實現界面。但是這會導致大量重復代碼,因此考慮使用循環渲染實現,先定義數據類型Item,接著定義數據items,再使用foreach循環渲染數據到界面,將寫死的數據從items里取出即可。

      class Item {
        name: string //小寫
        image: ResourceStr
        price: number
      
        constructor(name: string, image: ResourceStr, price: number) {
          this.name = name
          this.image = image
          this.price = price
        }
      }
      
      @Entry
      @Component
      struct ProductListPage {
        // 商品數據
        private items: Array<Item> = [
          new Item('華為Mate60', $r('app.media.mate60'),6999),
          new Item('MateBookProX', $r('app.media.mate60'),13999),
          new Item('WatchGT4', $r('app.media.mate60'),1438),
          new Item('FreeBuds Pro3', $r('app.media.mate60'),1499),
          new Item('Mate X5', $r('app.media.mate60'),12999)
        ]
      
        build() {
          Column({ space: 8 }) {
            // 標題
            Row() {
              Text('商品列表')
                .fontSize(30)
                .fontWeight(FontWeight.Bold)
            }
            .width('100%')
            .margin({ bottom: 20 })
      
            // 商品列表
            ForEach(
              this.items,
              (item:Item)=>{
                Row({ space: 10 }) {
                  Image(item.image)
                    .width(100)
                  Column({ space: 4 }) {
                    Text(item.name)
                      .fontSize(20)
                      .fontWeight(FontWeight.Bold)
                    Text('¥'+item.price)
                      .fontColor('#F36')
                      .fontSize(18)
                  }
                  .height('100%')
                  .alignItems(HorizontalAlign.Start)
                }
                .width('100%')
                .backgroundColor('#FFF')
                .borderRadius(20)
                .height(120)
                .padding(10)
              }
            )
          }
          .width('100%')
          .height('100%')
          .backgroundColor('#EFEFEF')
          .padding(20)
        }
      }
      

      效果圖

      2循環列表

      1.2.3 數據條件渲染

      有的商品參加打折活動,會多一個折扣價,因此需要根據商品是否打折顯示不同的價格信息。

      首先修改商品數據類型,添加折扣discount字段;然后再打折商品上添加折扣價;最后再通過條件渲染界面。

      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 ProductListPage {
        // 商品數據
        private items: Array<Item> = [
          new Item('華為Mate60', $r('app.media.mate60'),6999, 500),
          new Item('MateBookProX', $r('app.media.mate60'),13999),
          new Item('WatchGT4', $r('app.media.mate60'),1438),
          new Item('FreeBuds Pro3', $r('app.media.mate60'),1499),
          new Item('Mate X5', $r('app.media.mate60'),12999)
        ]
      
        build() {
          Column({ space: 8 }) {
            // 標題
            Row() {
              Text('商品列表')
                .fontSize(30)
                .fontWeight(FontWeight.Bold)
            }
            .width('100%')
            .margin({ bottom: 20 })
      
            // 商品列表
            ForEach(
              this.items,
              (item:Item)=>{
                Row({ space: 10 }) {
                  Image(item.image)
                    .width(100)
                  Column({ space: 4 }) {
                    if(item.discount){
                      Text(item.name)
                        .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(item.name)
                        .fontSize(20)
                        .fontWeight(FontWeight.Bold)
                      Text('¥'+item.price)
                        .fontColor('#F36')
                        .fontSize(18)
                    }
                  }
                  .height('100%')
                  .alignItems(HorizontalAlign.Start)
                }
                .width('100%')
                .backgroundColor('#FFF')
                .borderRadius(20)
                .height(120)
                .padding(10)
              }
            )
          }
          .width('100%')
          .height('100%')
          .backgroundColor('#EFEFEF')
          .padding(20)
        }
      }
      

      效果圖

      3折扣價列表

      《鴻蒙應用開發從入門到項目實戰》系列文章持續更新中,陸續更新AI+編程、企業級項目實戰等原創內容,防止迷路,歡迎關注!

      posted @ 2025-09-28 09:15  程序員潘Sir  閱讀(268)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 精品黄色av一区二区三区| 国产成人一区二区三区免费| 日韩精品亚洲专在线电影| 国产一区二区一卡二卡| Y111111国产精品久久久| 香蕉久久久久久久AV网站| 精品久久久久久中文字幕202| 精品无码一区在线观看| 熟女视频一区二区三区嫩草| 欧美自拍另类欧美综合图片区| 国产精品熟女孕妇一区二区| 一区二区在线欧美日韩中文| 久久精品国产福利一区二区| brazzers欧美巨大| 狠狠躁夜夜躁无码中文字幕| 亚洲高清aⅴ日本欧美视频| 丁香五月亚洲综合在线国内自拍 | 成人亚欧欧美激情在线观看| 福利视频在线一区二区| 中文字幕日本一区二区在线观看 | 暖暖免费观看电视在线高清| 亚洲av无在线播放中文| 国产在线观看免费观看| 国产精品亚洲一区二区z| 黑人巨大无码中文字幕无码| 亚洲天码中文字幕第一页| 在线涩涩免费观看国产精品| 无码人妻斩一区二区三区| 乱人伦中文字幕成人网站在线| 中文字幕日韩精品人妻| 永久免费无码av在线网站| 精品久久久久久国产| 国精品午夜福利不卡视频| 资兴市| 色悠久久网国产精品99| 国语精品自产拍在线观看网站| 亚洲国产午夜精品理论片妓女| 91久久夜色精品国产网站| 东京热人妻无码一区二区av| 国产在线观看网址不卡一区| 国产婷婷综合在线视频|