赞
踩
Lottie是一个适用于OpenHarmony的动画库,它可以解析Adobe After Effects软件通过Bodymovin插件导出的json格式的动画,并在移动设备上进行本地渲染, 可以在各种屏幕尺寸和分辨率上呈现,并且支持动画的交互性,通过添加触摸事件或其他用户交互操作,使动画更加生动和具有响应性。
使用说明:
1.进入页面,点击动画卡片,动画播放并且文本发生变化。
{
"name": "lottieview",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "Index.ets",
"author": "",
"license": "Apache-2.0",
"dependencies": {
// Lottie模块
"@ohos/lottie": "2.0.0",
}
}
将Lottie的资源文件data.json文件放置到Entry目录下的common文件夹下(放置本模块中,使用相对路径无法读取)。数据参考politeChicky.json
进入页面,通过Canvas的onReady函数加载动画,点击播放动画,动画执行播放,文本刷新。源码参考LotieView.ets
// 加载动画 loadAnimation(autoplay: boolean) { if (this.animateItem !== null) { this.animateItem.destroy(); this.animateItem = null; } // TODO:知识点:lottie.loadAnimation将json数据生成动画 this.animateItem = lottie.loadAnimation({ container: this.politeChickyController, renderer: 'canvas', loop: false, autoplay: autoplay, name: this.politeChicky, path: this.politeChickyPath, initialSegment: [FRAME_START, FRAME_END] }) } build() { Stack({ alignContent: Alignment.TopStart }) { // 动画 Canvas(this.politeChickyController) .width($r('app.integer.canvas_size')) .height($r('app.integer.canvas_size')) .backgroundColor($r('app.color.ohos_id_color_palette2')) .borderRadius($r('app.string.ohos_id_corner_radius_default_m')) .onReady(() => { this.loadAnimation(false); }) .onClick(() => { this.loadAnimation(true); this.times++; }) // 响应动画的文本 Text(this.textArray[this.times % TEXT_DATA_LENGTH]) .fontSize($r('app.string.ohos_id_text_size_headline')) .margin($r('app.string.ohos_id_elements_margin_vertical_m')) .fontColor(Color.White) }.margin({ top: $r('app.string.ohos_id_elements_margin_vertical_l') }) } }
不涉及。
lottieview // har类型
|---view
| |---LottieView.ets // 视图层-应用主页面
本实例依赖common模块来实现日志的打印、资源 的调用、动态路由模块来实现页面的动态加载以及Lottie模块,版本为2.0.0。
为了能让大家更好的学习鸿蒙(HarmonyOS NEXT)开发技术,这边特意整理了《鸿蒙开发学习手册》(共计890页),希望对大家有所帮助:https://qr21.cn/FV7h05
https://qr21.cn/FV7h05
https://qr21.cn/FV7h05
https://qr21.cn/FV7h05
https://qr18.cn/F781PH
https://qr18.cn/F781PH
1.项目开发必备面试题
2.性能优化方向
3.架构方向
4.鸿蒙开发系统底层方向
5.鸿蒙音视频开发方向
6.鸿蒙车载开发方向
7.鸿蒙南向开发方向
https://qr21.cn/D2k9D5
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。