使用ZYNQ芯片和LVGL框架实现用户高刷新UI设计系列教程(第四十讲)

Lottie是一种用于在应用中显示动画的格式,lvgl lottie控件运行在lvgl项目中使用lottie动画。

以下是在GUI-Guider中的使用:

1.依赖

在网上下载有关lottie格式的文件例如".json",然后在lv_conf.h中启用lottie支持

#define LV_USE_Lottie 1

2.使用

1从文件中使用rlottie

要从文件使用创建 Lottie 动画:

lv_obj_t * lottie = lv_rlottie_create_from_file(parent, width, height, "path/to/lottie.json");

请注意,Rlottie 使用标准的 STDIO C 文件 API,因此您可以使用 路径"通常",不需要特定于 LVGL 的驱动程序号。

2从原始字符串数据使用rlottie

lv_example_rlottie_approve.c 包含 RAW 格式的示例动画格式。而不是存储 JSON 字符串,而是为原因如下:

• 避免在 JSON 文件中转义字符 "

• 某些编译器不支持很长的字符串

lvgl/scripts/filetohex.py 可用于将 Lottie 文件转换为十六进制数组。例如:

./filetohex.py path/to/lottie.json > out.txt

要从原始数据创建动画:

extern const uint8_t lottie_data\[\];

lv_obj_t* lottie = lv_rlottie_create_from_raw(parent, width, height, (const char *)lottie_data);

3.获取与控制

Lottie 是标准且流行的格式,因此您可以找到许多动画 Web 上的文件。例如:https://lottiefiles.com/

LVGL 提供了两个功能来控制动画模式:lv_rlottie_set_play_mode() 和 lv_rlottie_set_current_frame() 。 在调用第一种方法时,您将结合您的意图,例如 这些示例:

lv_obj_t * lottie = lv_rlottie_create_from_file(scr, 128, 128, "test.json");

lv_obj_center(lottie);

// Pause to a specific frame

lv_rlottie_set_current_frame(lottie, 50);

lv_rlottie_set_play_mode(lottie, LV_RLOTTIE_CTRL_PAUSE); // The specified frame will be displayed and then the animation will pause

// Play backward and loop

lv_rlottie_set_play_mode(lottie, LV_RLOTTIE_CTRL_PLAY | LV_RLOTTIE_CTRL_BACKWARD | LV_RLOTTIE_CTRL_LOOP);

// Play forward once (no looping)

lv_rlottie_set_play_mode(lottie, LV_RLOTTIE_CTRL_PLAY | LV_RLOTTIE_CTRL_FORWARD);

默认动画模式是 循环向前播放 。

如果不启用循环,则在 LV_EVENT_READY 没有循环,动画就无法取得更大的进步。

为了获得动画中的帧数或当前帧索引,可以将 lv_obj_t 实例强制转换为 :c:struct: lv_rlottie_t 实例并检查 current_frame 和 total_frames 成员。

本文章由威三学社出品

对课程感兴趣可以私信联系

相关推荐
johnny2334 小时前
UI新革命?GenUI、WanDB-OpenUI、thesysdev-OpenUI、A2UI、AG-UI、MCP-UI
ui
天天进步201513 小时前
UI-TARS 源码解析 #10:parse_action 源码解析:如何用 AST 安全解析模型生成的函数调用?
安全·ui
FuckPatience1 天前
Telerik UI for WPF 值不能为null。参数名:key
ui·wpf
breeze jiang1 天前
从原生事件到 React 组件化:用状态驱动模型加载进度 UI
前端·react.js·ui
JaneConan2 天前
鸿蒙 ArkUI 深水区:@Watch 和 @Observed,状态变了「自动跑」+ 嵌套对象「深层重绘」
开发语言·后端·ui·harmonyos
施棠海2 天前
Pixel2XML实战:10分钟从设计稿做出一个能拨号的Android拨号盘页面(附完整业务代码)
android·java·ui
施棠海2 天前
设计稿一键变成可运行的Android页面:Pixel2XML全流程UI开发框架实战(附完整源码)
android·ui·架构
Helen_cai2 天前
OpenHarmony 通用状态加载、空页面、错误兜底组件封装(全局业务通用 UI 组件 API23)
开发语言·ui·华为·php·harmonyos
YM52e2 天前
鸿蒙 Flutter BoxDecoration装饰:打造精美UI效果
学习·flutter·ui·华为·harmonyos·鸿蒙
qq_463408422 天前
# 基于 HarmonyOS ArkTS 声明式 UI 构建智能音乐播放器:深色主题圆盘轮播、五 Tab 导航隔离、瀑布流收藏与悬浮迷你播放条实现深度解析
ui·华为·harmonyos