69.[HarmonyOS NEXT 实战案例九] 旅游景点网格布局(上)

简介: 本教程将详细讲解如何使用HarmonyOS NEXT中的GridRow和GridCol组件实现旅游景点网格布局。通过网格布局,我们可以以美观、规整的方式展示各种旅游景点信息,为用户提供良好的浏览体验。

[HarmonyOS NEXT 实战案例九] 旅游景点网格布局(上)

项目已开源,开源地址: https://gitcode.com/nutpi/HarmonyosNextCaseStudyTutorial , 欢迎fork & star

效果演示

img_4276b4e4.png

1. 概述

本教程将详细讲解如何使用HarmonyOS NEXT中的GridRow和GridCol组件实现旅游景点网格布局。通过网格布局,我们可以以美观、规整的方式展示各种旅游景点信息,为用户提供良好的浏览体验。

本教程将涵盖以下内容:

  • 旅游景点数据结构设计
  • 数据准备
  • 整体布局实现
  • GridRow和GridCol组件配置
  • 景点卡片实现
  • 布局效果分析

2. 数据结构设计

首先,我们需要定义旅游景点的数据结构,包含景点的基本信息:

// 旅游景点数据类型
export interface SpotType {
   
  id: number;         // 景点ID
  name: string;       // 景点名称
  image: Resource;    // 景点图片
  location: string;   // 景点位置
  price: number;      // 门票价格
  rating: number;     // 评分
  tags: string[];     // 标签
  description: string; // 景点描述
}

3. 数据准备

接下来,我们准备一些示例数据用于展示:

// 旅游景点数据
private spots: SpotType[] = [
  {
   
    id: 1,
    name: '长城',
    image: $r('app.media.great_wall'),
    location: '北京',
    price: 60,
    rating: 4.8,
    tags: ['历史', '文化', '世界遗产'],
    description: '长城是中国古代的伟大防御工程,也是世界上最伟大的建筑之一。'
  },
  {
   
    id: 2,
    name: '西湖',
    image: $r('app.media.west_lake'),
    location: '杭州',
    price: 0,
    rating: 4.7,
    tags: ['自然', '风景', '文化'],
    description: '西湖是中国浙江省杭州市区西面的淡水湖,被誉为人间天堂。'
  },
  {
   
    id: 3,
    name: '故宫',
    image: $r('app.media.forbidden_city'),
    location: '北京',
    price: 80,
    rating: 4.9,
    tags: ['历史', '文化', '世界遗产'],
    description: '故宫是中国明清两代的皇家宫殿,是世界上现存规模最大、保存最为完整的木质结构古建筑之一。'
  },
  {
   
    id: 4,
    name: '黄山',
    image: $r('app.media.huangshan'),
    location: '安徽',
    price: 190,
    rating: 4.8,
    tags: ['自然', '风景', '世界遗产'],
    description: '黄山以奇松、怪石、云海、温泉、冬雪五绝著称于世,被誉为"天下第一奇山"。'
  },
  {
   
    id: 5,
    name: '张家界',
    image: $r('app.media.zhangjiajie'),
    location: '湖南',
    price: 248,
    rating: 4.7,
    tags: ['自然', '风景', '世界遗产'],
    description: '张家界以其独特的石英砂岩峰林地貌闻名于世,被誉为"三千奇峰,八百秀水"。'
  },
  {
   
    id: 6,
    name: '九寨沟',
    image: $r('app.media.jiuzhaigou'),
    location: '四川',
    price: 190,
    rating: 4.9,
    tags: ['自然', '风景', '世界遗产'],
    description: '九寨沟以其彩池、瀑布、雪山、森林闻名于世,被誉为"童话世界"。'
  },
  {
   
    id: 7,
    name: '丽江古城',
    image: $r('app.media.lijiang'),
    location: '云南',
    price: 80,
    rating: 4.6,
    tags: ['历史', '文化', '古镇'],
    description: '丽江古城是中国历史文化名城,以其独特的纳西族建筑和水系闻名于世。'
  },
  {
   
    id: 8,
    name: '鼓浪屿',
    image: $r('app.media.gulangyu'),
    location: '厦门',
    price: 35,
    rating: 4.5,
    tags: ['文化', '海岛', '音乐'],
    description: '鼓浪屿是厦门的一个小岛,以其钢琴文化和欧式建筑闻名,被誉为"钢琴之岛"。'
  }
];

4. 布局实现

4.1 整体布局结构

我们将使用Column作为最外层容器,包含顶部搜索栏、分类标签栏和景点网格列表:

build() {
   
  Column() {
   
    // 顶部搜索栏
    this.SearchBar()

    // 分类标签栏
    this.CategoryTabs()

    // 景点网格列表
    this.SpotGrid()
  }
  .width('100%')
  .height('100%')
  .backgroundColor('#F5F5F5')
}

4.2 顶部搜索栏

@Builder
private SearchBar() {
   
  Row() {
   
    // 搜索框
    Row() {
   
      Image($r('app.media.ic_search'))
        .width(20)
        .height(20)
        .margin({
    right: 8 })

      TextInput({
    placeholder: '搜索目的地、景点' })
        .layoutWeight(1)
        .backgroundColor('transparent')
        .placeholderColor('#999999')
        .fontSize(14)
        .height('100%')
    }
    .width('85%')
    .height(40)
    .backgroundColor(Color.White)
    .borderRadius(20)
    .padding({
    left: 12, right: 12 })

    // 筛选按钮
    Image($r('app.media.ic_filter'))
      .width(24)
      .height(24)
      .margin({
    left: 12 })
  }
  .width('100%')
  .padding({
    left: 16, right: 16, top: 12, bottom: 12 })
  .backgroundColor('#1976D2')
}

4.3 分类标签栏

@State currentCategory: string = '推荐';
private categories: string[] = ['推荐', '热门', '自然风光', '历史文化', '主题公园', '海岛', '古镇'];

@Builder
private CategoryTabs() {
   
  Scroll(ScrollDirection.Horizontal) {
   
    Row() {
   
      ForEach(this.categories, (category: string) => {
   
        Text(category)
          .fontSize(14)
          .fontColor(this.currentCategory === category ? '#1976D2' : '#666666')
          .fontWeight(this.currentCategory === category ? FontWeight.Bold : FontWeight.Normal)
          .padding({
    left: 16, right: 16, top: 12, bottom: 12 })
          .backgroundColor(this.currentCategory === category ? '#E3F2FD' : 'transparent')
          .borderRadius(16)
          .margin({
    right: 8 })
          .onClick(() => {
   
            this.currentCategory = category;
          })
      })
    }
    .padding({
    left: 16, right: 16 })
  }
  .scrollBar(BarState.Off)
  .width('100%')
}

4.4 景点网格列表

这是本教程的核心部分,我们使用GridRow和GridCol组件实现景点网格列表:

@Builder
private SpotGrid() {
   
  Scroll() {
   
    Column() {
   
      // 推荐景点标题
      Row() {
   
        Text('推荐景点')
          .fontSize(18)
          .fontWeight(FontWeight.Bold)
          .fontColor('#333333')

        Blank()

        Text('查看更多 >')
          .fontSize(14)
          .fontColor('#1976D2')
      }
      .width('100%')
      .padding({
    left: 16, right: 16, top: 16, bottom: 8 })

      // 使用GridRow和GridCol实现网格布局
      GridRow({
   
        columns: {
    xs: 1, sm: 2, md: 3, lg: 4 },
        gutter: {
    x: 16, y: 16 }
      }) {
   
        ForEach(this.spots, (spot: SpotType) => {
   
          GridCol() {
   
            this.SpotCard(spot)
          }
        })
      }
      .width('100%')
      .padding(16)
    }
    .width('100%')
  }
  .scrollBar(BarState.Off)
  .scrollable(ScrollDirection.Vertical)
  .width('100%')
  .layoutWeight(1)
}

4.5 景点卡片实现

@Builder
private SpotCard(spot: SpotType) {
   
  Column() {
   
    // 景点图片
    Stack() {
   
      Image(spot.image)
        .width('100%')
        .height(160)
        .borderRadius({
    topLeft: 8, topRight: 8 })
        .objectFit(ImageFit.Cover)

      // 价格标签
      Text(spot.price === 0 ? '免费' : ${
     spot.price}`)
        .fontSize(12)
        .fontColor(Color.White)
        .backgroundColor(spot.price === 0 ? '#4CAF50' : '#FF5722')
        .borderRadius(4)
        .padding({
    left: 6, right: 6, top: 2, bottom: 2 })
        .position({
    x: 8, y: 8 })
    }
    .width('100%')

    // 景点信息
    Column() {
   
      // 景点名称和评分
      Row() {
   
        Text(spot.name)
          .fontSize(16)
          .fontWeight(FontWeight.Bold)
          .fontColor('#333333')
          .maxLines(1)
          .textOverflow({
    overflow: TextOverflow.Ellipsis })

        Blank()

        Row() {
   
          Image($r('app.media.ic_star'))
            .width(16)
            .height(16)
            .margin({
    right: 4 })

          Text(spot.rating.toString())
            .fontSize(14)
            .fontColor('#FFB300')
        }
      }
      .width('100%')
      .margin({
    bottom: 8 })

      // 景点位置
      Row() {
   
        Image($r('app.media.ic_location'))
          .width(16)
          .height(16)
          .margin({
    right: 4 })

        Text(spot.location)
          .fontSize(14)
          .fontColor('#666666')
      }
      .width('100%')
      .margin({
    bottom: 8 })

      // 景点标签
      Row() {
   
        ForEach(spot.tags, (tag: string, index: number) => {
   
          if (index < 3) {
    // 最多显示3个标签
            Text(tag)
              .fontSize(12)
              .fontColor('#1976D2')
              .backgroundColor('#E3F2FD')
              .borderRadius(4)
              .padding({
    left: 6, right: 6, top: 2, bottom: 2 })
              .margin({
    right: 4 })
          }
        })
      }
      .width('100%')
    }
    .width('100%')
    .padding(12)
  }
  .width('100%')
  .backgroundColor(Color.White)
  .borderRadius(8)
}

5. GridRow和GridCol配置详解

在本案例中,我们使用了GridRow和GridCol组件实现网格布局。下面详细解析其配置:

5.1 GridRow配置

GridRow({
   
  columns: {
    xs: 1, sm: 2, md: 3, lg: 4 },
  gutter: {
    x: 16, y: 16 }
})
  • columns:定义不同屏幕尺寸下的列数

    • xs: 1:极小屏幕(如小型手机)显示1列
    • sm: 2:小屏幕(如大型手机)显示2列
    • md: 3:中等屏幕(如平板)显示3列
    • lg: 4:大屏幕(如桌面)显示4列
  • gutter:定义网格间的间距

    • x: 16:水平间距为16像素
    • y: 16:垂直间距为16像素

5.2 GridCol配置

在本案例中,我们使用了默认的GridCol配置,没有指定span属性,这意味着每个景点卡片占据一个网格单元。

GridCol() {
   
  this.SpotCard(spot)
}

如果需要某些景点卡片占据更多的空间,可以通过span属性进行配置:

GridCol({
   
  span: {
    xs: 1, sm: 2, md: 1, lg: 1 }
}) {
   
  this.SpotCard(spot)
}

这样配置后,在小屏幕(sm)上,该景点卡片会占据2列,而在其他屏幕尺寸上占据1列。

6. 布局效果分析

6.1 响应式布局

通过GridRow的columns配置,我们实现了响应式布局,使应用能够适应不同屏幕尺寸的设备:

屏幕尺寸 列数 效果
极小屏幕(xs) 1列 每行显示1个景点卡片
小屏幕(sm) 2列 每行显示2个景点卡片
中等屏幕(md) 3列 每行显示3个景点卡片
大屏幕(lg) 4列 每行显示4个景点卡片

6.2 网格间距

通过GridRow的gutter配置,我们设置了网格间的间距为16像素,使布局更加美观、清晰。

6.3 景点卡片设计

每个景点卡片包含以下元素:

  • 景点图片:展示景点的视觉效果
  • 价格标签:显示门票价格或免费标识
  • 景点名称:突出显示景点名称
  • 评分:使用星星图标和数字展示评分
  • 位置:显示景点所在地
  • 标签:展示景点的特点和分类

这种设计使用户能够快速获取景点的关键信息,便于做出选择。

7. GridRow和GridCol组件详解

7.1 GridRow组件

GridRow是HarmonyOS NEXT提供的网格行容器组件,用于创建网格布局。它具有以下主要属性:

属性 类型 描述
columns number \ { xs?: number, sm?: number, md?: number, lg?: number, xl?: number, xxl?: number } 当前行的总列数
gutter number \ { x?: number, y?: number } 栅格间隔
breakpoints { value: number, reference: BreakpointsReference }[] 自定义断点值

7.2 GridCol组件

GridCol是HarmonyOS NEXT提供的网格列容器组件,用于在GridRow中创建网格列。它具有以下主要属性:

属性 类型 描述
span number \ { xs?: number, sm?: number, md?: number, lg?: number, xl?: number, xxl?: number } 列宽度
offset number \ { xs?: number, sm?: number, md?: number, lg?: number, xl?: number, xxl?: number } 列偏移量
order number \ { xs?: number, sm?: number, md?: number, lg?: number, xl?: number, xxl?: number } 列顺序

8. 完整代码

@Entry
@Component
struct TravelSpotGrid {
   
  // 旅游景点数据类型
  interface SpotType {
   
    id: number;         // 景点ID
    name: string;       // 景点名称
    image: Resource;    // 景点图片
    location: string;   // 景点位置
    price: number;      // 门票价格
    rating: number;     // 评分
    tags: string[];     // 标签
    description: string; // 景点描述
  }

  // 旅游景点数据
  private spots: SpotType[] = [
    {
   
      id: 1,
      name: '长城',
      image: $r('app.media.great_wall'),
      location: '北京',
      price: 60,
      rating: 4.8,
      tags: ['历史', '文化', '世界遗产'],
      description: '长城是中国古代的伟大防御工程,也是世界上最伟大的建筑之一。'
    },
    {
   
      id: 2,
      name: '西湖',
      image: $r('app.media.west_lake'),
      location: '杭州',
      price: 0,
      rating: 4.7,
      tags: ['自然', '风景', '文化'],
      description: '西湖是中国浙江省杭州市区西面的淡水湖,被誉为人间天堂。'
    },
    {
   
      id: 3,
      name: '故宫',
      image: $r('app.media.forbidden_city'),
      location: '北京',
      price: 80,
      rating: 4.9,
      tags: ['历史', '文化', '世界遗产'],
      description: '故宫是中国明清两代的皇家宫殿,是世界上现存规模最大、保存最为完整的木质结构古建筑之一。'
    },
    {
   
      id: 4,
      name: '黄山',
      image: $r('app.media.huangshan'),
      location: '安徽',
      price: 190,
      rating: 4.8,
      tags: ['自然', '风景', '世界遗产'],
      description: '黄山以奇松、怪石、云海、温泉、冬雪五绝著称于世,被誉为"天下第一奇山"。'
    },
    {
   
      id: 5,
      name: '张家界',
      image: $r('app.media.zhangjiajie'),
      location: '湖南',
      price: 248,
      rating: 4.7,
      tags: ['自然', '风景', '世界遗产'],
      description: '张家界以其独特的石英砂岩峰林地貌闻名于世,被誉为"三千奇峰,八百秀水"。'
    },
    {
   
      id: 6,
      name: '九寨沟',
      image: $r('app.media.jiuzhaigou'),
      location: '四川',
      price: 190,
      rating: 4.9,
      tags: ['自然', '风景', '世界遗产'],
      description: '九寨沟以其彩池、瀑布、雪山、森林闻名于世,被誉为"童话世界"。'
    },
    {
   
      id: 7,
      name: '丽江古城',
      image: $r('app.media.lijiang'),
      location: '云南',
      price: 80,
      rating: 4.6,
      tags: ['历史', '文化', '古镇'],
      description: '丽江古城是中国历史文化名城,以其独特的纳西族建筑和水系闻名于世。'
    },
    {
   
      id: 8,
      name: '鼓浪屿',
      image: $r('app.media.gulangyu'),
      location: '厦门',
      price: 35,
      rating: 4.5,
      tags: ['文化', '海岛', '音乐'],
      description: '鼓浪屿是厦门的一个小岛,以其钢琴文化和欧式建筑闻名,被誉为"钢琴之岛"。'
    }
  ];

  @State currentCategory: string = '推荐';
  private categories: string[] = ['推荐', '热门', '自然风光', '历史文化', '主题公园', '海岛', '古镇'];

  build() {
   
    Column() {
   
      // 顶部搜索栏
      this.SearchBar()

      // 分类标签栏
      this.CategoryTabs()

      // 景点网格列表
      this.SpotGrid()
    }
    .width('100%')
    .height('100%')
    .backgroundColor('#F5F5F5')
  }

  @Builder
  private SearchBar() {
   
    Row() {
   
      // 搜索框
      Row() {
   
        Image($r('app.media.ic_search'))
          .width(20)
          .height(20)
          .margin({
    right: 8 })

        TextInput({
    placeholder: '搜索目的地、景点' })
          .layoutWeight(1)
          .backgroundColor('transparent')
          .placeholderColor('#999999')
          .fontSize(14)
          .height('100%')
      }
      .width('85%')
      .height(40)
      .backgroundColor(Color.White)
      .borderRadius(20)
      .padding({
    left: 12, right: 12 })

      // 筛选按钮
      Image($r('app.media.ic_filter'))
        .width(24)
        .height(24)
        .margin({
    left: 12 })
    }
    .width('100%')
    .padding({
    left: 16, right: 16, top: 12, bottom: 12 })
    .backgroundColor('#1976D2')
  }

  @Builder
  private CategoryTabs() {
   
    Scroll(ScrollDirection.Horizontal) {
   
      Row() {
   
        ForEach(this.categories, (category: string) => {
   
          Text(category)
            .fontSize(14)
            .fontColor(this.currentCategory === category ? '#1976D2' : '#666666')
            .fontWeight(this.currentCategory === category ? FontWeight.Bold : FontWeight.Normal)
            .padding({
    left: 16, right: 16, top: 12, bottom: 12 })
            .backgroundColor(this.currentCategory === category ? '#E3F2FD' : 'transparent')
            .borderRadius(16)
            .margin({
    right: 8 })
            .onClick(() => {
   
              this.currentCategory = category;
            })
        })
      }
      .padding({
    left: 16, right: 16 })
    }
    .scrollBar(BarState.Off)
    .width('100%')
  }

  @Builder
  private SpotGrid() {
   
    Scroll() {
   
      Column() {
   
        // 推荐景点标题
        Row() {
   
          Text('推荐景点')
            .fontSize(18)
            .fontWeight(FontWeight.Bold)
            .fontColor('#333333')

          Blank()

          Text('查看更多 >')
            .fontSize(14)
            .fontColor('#1976D2')
        }
        .width('100%')
        .padding({
    left: 16, right: 16, top: 16, bottom: 8 })

        // 使用GridRow和GridCol实现网格布局
        GridRow({
   
          columns: {
    xs: 1, sm: 2, md: 3, lg: 4 },
          gutter: {
    x: 16, y: 16 }
        }) {
   
          ForEach(this.spots, (spot: SpotType) => {
   
            GridCol() {
   
              this.SpotCard(spot)
            }
          })
        }
        .width('100%')
        .padding(16)
      }
      .width('100%')
    }
    .scrollBar(BarState.Off)
    .scrollable(ScrollDirection.Vertical)
    .width('100%')
    .layoutWeight(1)
  }

  @Builder
  private SpotCard(spot: SpotType) {
   
    Column() {
   
      // 景点图片
      Stack() {
   
        Image(spot.image)
          .width('100%')
          .height(160)
          .borderRadius({
    topLeft: 8, topRight: 8 })
          .objectFit(ImageFit.Cover)

        // 价格标签
        Text(spot.price === 0 ? '免费' : ${
     spot.price}`)
          .fontSize(12)
          .fontColor(Color.White)
          .backgroundColor(spot.price === 0 ? '#4CAF50' : '#FF5722')
          .borderRadius(4)
          .padding({
    left: 6, right: 6, top: 2, bottom: 2 })
          .position({
    x: 8, y: 8 })
      }
      .width('100%')

      // 景点信息
      Column() {
   
        // 景点名称和评分
        Row() {
   
          Text(spot.name)
            .fontSize(16)
            .fontWeight(FontWeight.Bold)
            .fontColor('#333333')
            .maxLines(1)
            .textOverflow({
    overflow: TextOverflow.Ellipsis })

          Blank()

          Row() {
   
            Image($r('app.media.ic_star'))
              .width(16)
              .height(16)
              .margin({
    right: 4 })

            Text(spot.rating.toString())
              .fontSize(14)
              .fontColor('#FFB300')
          }
        }
        .width('100%')
        .margin({
    bottom: 8 })

        // 景点位置
        Row() {
   
          Image($r('app.media.ic_location'))
            .width(16)
            .height(16)
            .margin({
    right: 4 })

          Text(spot.location)
            .fontSize(14)
            .fontColor('#666666')
        }
        .width('100%')
        .margin({
    bottom: 8 })

        // 景点标签
        Row() {
   
          ForEach(spot.tags, (tag: string, index: number) => {
   
            if (index < 3) {
    // 最多显示3个标签
              Text(tag)
                .fontSize(12)
                .fontColor('#1976D2')
                .backgroundColor('#E3F2FD')
                .borderRadius(4)
                .padding({
    left: 6, right: 6, top: 2, bottom: 2 })
                .margin({
    right: 4 })
            }
          })
        }
        .width('100%')
      }
      .width('100%')
      .padding(12)
    }
    .width('100%')
    .backgroundColor(Color.White)
    .borderRadius(8)
  }
}

9. 总结

本教程详细讲解了如何使用HarmonyOS NEXT中的GridRow和GridCol组件实现旅游景点网格布局。通过合理的数据结构设计、精心的UI设计和灵活的GridRow配置,我们实现了一个美观、响应式的旅游景点展示页面。

相关文章
|
29天前
|
测试技术 开发工具 开发者
HarmonyOS Next快速入门:了解项目工程目录结构
本教程旨在帮助开发者快速上手HarmonyOS应用开发,涵盖从环境搭建到工程创建的全流程。通过DevEco Studio创建首个项目时,选择“Application”与“Empty Ability”,配置项目名称、包名、保存路径等关键信息后完成创建。代码示例展示了基本UI组件的使用,如`Hello World`文本显示与交互逻辑。此外,详细解析了工程目录结构,包括AppScope自动生成规则、主模块(entry)的功能划分、依赖配置文件(oh-package.json5)的作用,以及app.json5中包名、版本号等全局配置项的含义。
72 5
|
24天前
|
开发者 UED
HarmonyOS Next快速入门:通用属性
本教程以《HarmonyOS Next快速入门》为基础,涵盖应用开发核心技能。通过代码实例讲解尺寸、位置、布局约束、Flex布局、边框、背景及图像效果等属性设置方法。如`.width()`调整宽度,`.align()`设定对齐方式,`.border()`配置边框样式,以及模糊、阴影等视觉效果的实现。结合实际案例,帮助开发者掌握HarmonyOS组件属性的灵活运用,提升开发效率与用户体验。适合初学者及进阶开发者学习。
64 0
|
24天前
|
开发者
HarmonyOS Next快速入门:通用事件
本教程聚焦HarmonyOS应用开发,涵盖事件处理的核心内容。包括事件分发、触屏事件、键鼠事件、焦点事件及拖拽事件等。通过代码实例讲解点击事件、触控事件(Down/Move/Up)、获焦与失焦事件的处理逻辑,以及气泡弹窗的应用。适合开发者快速掌握HarmonyOS Next中通用事件的使用方法,提升应用交互体验。
63 0
|
24天前
|
开发者 容器
HarmonyOS Next快速入门:Button组件
本教程摘自《HarmonyOS Next快速入门》,聚焦HarmonyOS应用开发中的Button组件。Button支持胶囊、圆形和普通三种类型,可通过子组件实现复杂功能,如嵌入图片或文字。支持自定义样式(边框弧度、文本样式、背景色等)及点击事件处理。示例代码展示了不同类型按钮的创建与交互逻辑,助开发者快速上手。适合HarmonyOS初学者及对UI组件感兴趣的开发者学习。
68 0
|
24天前
|
开发者
HarmonyOS Next快速入门:Image组件
本教程摘自《HarmonyOS Next快速入门》,专注于HarmonyOS应用开发中的Image组件使用。Image组件支持多种图片格式(如png、jpg、svg等),可渲染本地资源、网络图片、媒体库文件及PixelMap像素图。通过设置`objectFit`属性,实现不同缩放类型;利用`fillColor`属性调整矢量图颜色。示例代码涵盖本地、网络及资源图片的加载与样式设置,同时需在`module.json5`中声明网络权限以加载外部资源。适合开发者快速掌握HarmonyOS图像展示功能。
80 0
|
29天前
|
开发者
鸿蒙开发:资讯项目实战之项目初始化搭建
目前来说,我们的资讯项目只是往前迈了很小的一步,仅仅实现了项目创建,步虽小,但概念性的知识很多,这也是这个项目的初衷,让大家不仅仅可以掌握日常的技术开发,也能让大家理解实际的项目开发知识。
鸿蒙开发:资讯项目实战之项目初始化搭建
|
23天前
|
缓存 JavaScript IDE
鸿蒙开发:基于最新API,如何实现组件化运行
手动只是让大家了解切换的原理,在实际开发中,可不推荐手动,下篇文章,我们将通过脚本或者插件,快速实现组件化模块之间的切换,实现独立运行,敬请期待!
鸿蒙开发:基于最新API,如何实现组件化运行
|
1月前
|
SQL 弹性计算 数据库
鸿蒙5开发宝藏案例分享---优化应用时延问题
鸿蒙性能优化指南来了!从UI渲染到数据库操作,6大实战案例助你提升应用流畅度。布局层级优化、数据加载并发、数据库查询提速、相机资源延迟释放、手势识别灵敏调整及转场动画精调,全面覆盖性能痛点。附赠性能自检清单,帮助开发者高效定位问题,让应用运行如飞!来自华为官方文档的精华内容,建议收藏并反复研读,共同探讨更多优化技巧。
|
1月前
|
缓存
鸿蒙5开发宝藏案例分享---Swiper组件性能优化实战
本文分享了鸿蒙系统中Swiper组件的性能优化技巧,包括:1) 使用`LazyForEach`替代`ForEach`实现懒加载,显著降低内存占用;2) 通过`cachedCount`精准控制缓存数量,平衡流畅度与内存消耗;3) 利用`onAnimationStart`在抛滑时提前加载资源,提升构建效率;4) 添加`@Reusable`装饰器复用组件实例,减少创建开销。实际应用后,图库页帧率从45fps提升至58fps,效果显著。适合处理复杂列表或轮播场景,欢迎交流经验!
|
1月前
|
缓存 JavaScript 前端开发
鸿蒙5开发宝藏案例分享---Web开发优化案例分享
本文深入解读鸿蒙官方文档中的 `ArkWeb` 性能优化技巧,从预启动进程到预渲染,涵盖预下载、预连接、预取POST等八大优化策略。通过代码示例详解如何提升Web页面加载速度,助你打造流畅的HarmonyOS应用体验。内容实用,按需选用,让H5页面快到飞起!