HarmonyOS ArkTS 骨架屏加载显示(二十五)

目录

前言

所谓骨架屏,就是在页面进行耗时加载时,先展示的等待 UI, 以告知用户程序目前正在运行,稍等即可。 等待的UI大部分是 loading 转圈的弹窗,有的是自己风格的小动画。其实大同小异。而骨架屏无非也是一个等待的UI。基本是由各种灰色块组成,夹杂着一些代表特殊样式的其他浅颜色的色块。骨架屏的不用之处就在于这些灰色块的排列组合和真正展示出来的页面样式基本一致。因此骨架屏的展示除了告知用户程序正在加载外,还能让用户大概知道稍后将要展示的内容是什么,给了用户一些期待,从心理上,让用户更愿意等待一会。

1、骨架屏代码显示

bash 复制代码
/**
 * 骨架屏显示
 */
@Component
export struct ArticleSkeletonView {
  build() {
    Row() {
      Column() {
        textArea(80, 80)
      }
      .margin({ right: 20 })

      Column() {
        textArea('60%', 20)
        textArea('50%', 20)
      }
      .alignItems(HorizontalAlign.Start)
      .justifyContent(FlexAlign.SpaceAround)
      .height('100%')
    }
    .padding(20)
    .borderRadius(12)
    .backgroundColor('#FFECECEC')
    .height(120)
    .width('100%')
    .justifyContent(FlexAlign.SpaceBetween)
  }
}

@Builder
function textArea(width: number | Resource | string = '100%', height: number | Resource | string = '100%') {
  Row()
    .width(width)
    .height(height)
    .backgroundColor('#FFF2F3F4')
}

2、代码中引用

bash 复制代码
@Component
@Preview
export default  struct Index {
  @State message: string = '首页'
  webviewController: web_webview.WebviewController = new web_webview.WebviewController();
  @State simpleList: Array<number> = [1, 2, 3, 4, 5];
  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(30)
          .fontWeight(FontWeight.Bold)

        // Button('loadUrl')
        //   .onClick(() => {
        //     try {
        //       // 点击按钮时,通过loadUrl,跳转到www.example1.com
        //       this.webviewController.loadUrl('www.example.c1om');
        //     } catch (error) {
        //       console.error(`ErrorCode: ${error.code},  Message: ${error.message}`);
        //     }
        //   })
        // // 组件创建时,加载www.example.com
        // Web({ src: 'www.example.com', controller: this.webviewController })
        //

        ForEach(this.simpleList, (item: string) => {
          ArticleSkeletonView()
            .margin({ top: 20 })
        }, (item: string) => item)



      }
      .width('100%')
    }
    .height('100%')
  }

3、效果图展示

相关推荐
进击的丸子6 小时前
APP人脸识别增值版Harmony Demo实操与关键代码解析
前端·程序员·harmonyos
LEO111106 小时前
HarmonyOS应用开发实战:猫猫大作战-样式抽成可复用类,一处定义、多处复用,还能针对不同状态(正常/按下/禁用)应用不同样式
harmonyos·鸿蒙
starvapour10 小时前
在关机键损坏的情况下让手机关机
android·adb·手机
程序员黑豆10 小时前
鸿蒙应用开发:@Link 装饰器实现父子组件双向同步
前端·后端·harmonyos
2501_9197490310 小时前
华为鸿蒙免费解压缩APP—小羊解压缩
华为·harmonyos
爱写代码的森11 小时前
鸿蒙三方库 | harmony-utils之EncryptUtil URL编解码详解
服务器·华为·harmonyos·鸿蒙·huawei
youtootech11 小时前
HarmonyOS 6.0 卡片式信息流与瀑布流布局
华为·harmonyos
luoyayun36114 小时前
【Qt for Harmony】 Qt 5.12.12 鸿蒙版 Windows 交叉编译
qt·harmonyos·qt for harmony
木木子2215 小时前
# 鸿蒙 HarmonyOS 应用开发实战(第25期)|骰子(Dice Roller)— Unicode 符号与动画渲染精讲
华为·harmonyos
qizayaoshuap15 小时前
# HarmonyOS ArkTS 记忆翻牌游戏深度解析 —— Fisher-Yates 洗牌与翻牌匹配机制
游戏·华为·harmonyos