HarmonyOS NEXT应用开发案例——行程地址交换动画

249 篇文章 7 订阅
213 篇文章 2 订阅

介绍

本示例介绍使用显式动画 animateTo 实现左右地址交换动画。该场景多用于机票、火车票购买等出行类订票软件中。

效果预览图

使用说明

  1. 加载完成后显示地址交换动画页面,点击中间的图标,左右两边地址交换。

实现思路

  1. 创建左右两边Text组件显示地址。设置初始偏移量以及文本对齐方式。源码参考AddressExchangeView.ets
Row() {
  Text($r('app.string.address_exchange_address_left'))
    .translate({ x: this.translateX })
    .width($r('app.string.address_exchange_address_width'))
    .textAlign(this.swap ? TextAlign.End : TextAlign.Start)
  ...
  Text($r('app.string.address_exchange_address_right'))
    .translate({ x: -this.translateX })
    .width($r('app.string.address_exchange_address_width'))
    .textAlign(this.swap ? TextAlign.Start : TextAlign.End)
  ...
}
  1. 点击中间的图标时,修改是否切换的状态变量值和通过animateTo修改偏移量的值,来实现动态更新左右两边地址的显示,完成动画效果。源码参考AddressExchangeView.ets
Stack() {
  Image($r('app.media.address_exchange_airplane'))
    .size({
        height: $r('app.integer.address_exchange_airplane_size'),
        width: $r('app.integer.address_exchange_airplane_size')
    })
  Image($r('app.media.address_exchange_recycle'))
    .size({
        height: $r('app.integer.address_exchange_recycle_size'),
        width: $r('app.integer.address_exchange_recycle_size')
    })
    .rotate({ angle: this.rotateAngle })
    .animation({
        curve: Curve.EaseOut,
        playMode: PlayMode.Normal,
    })
}
  .width($r('app.string.address_exchange_image_width'))
  .onClick(() => {
    this.swap = !this.swap
    animateTo({ curve: curves.springMotion() }, () => {
        if (this.swap) {
            this.translateX = this.distance;
        } else {
            this.translateX = this.zeroTranslate;
        }
    })
    this.rotateAngle += this.rotateAddAngle;
  })

工程结构&模块类型

addressexchange                                            // har类型
|---view
|   |---AddressExchangeView.ets                            // 视图层-地址交换动画页面 

模块依赖

utils

参考资料

显式动画

为了能让大家更好的学习鸿蒙(HarmonyOS NEXT)开发技术,这边特意整理了《鸿蒙开发学习手册》(共计890页),希望对大家有所帮助:https://qr21.cn/FV7h05

《鸿蒙开发学习手册》:https://qr21.cn/FV7h05

入门必看:https://qr21.cn/FV7h05
1.  应用开发导读(ArkTS)
2.  ……

HarmonyOS 概念:https://qr21.cn/FV7h05

  1. 系统定义
  2. 技术架构
  3. 技术特性
  4. 系统安全

如何快速入门:https://qr21.cn/FV7h05
1.  基本概念
2.  构建第一个ArkTS应用
3.  ……

开发基础知识:https://qr21.cn/FV7h05
1.  应用基础知识
2.  配置文件
3.  应用数据管理
4.  应用安全管理
5.  应用隐私保护
6.  三方应用调用管控机制
7.  资源分类与访问
8.  学习ArkTS语言
9.  ……

基于ArkTS 开发:https://qr21.cn/FV7h05
1.  Ability开发
2.  UI开发
3.  公共事件与通知
4.  窗口管理
5.  媒体
6.  安全
7.  网络与链接
8.  电话服务
9.  数据管理
10.  后台任务(Background Task)管理
11.  设备管理
12.  设备使用信息统计
13.  DFX
14.  国际化开发
15.  折叠屏系列
16.  ……

鸿蒙开发面试真题(含参考答案):https://qr21.cn/FV7h05

  • 9
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值