鸿蒙(HarmonyOS)应用开发实战——标题下拉缩放案例

往期知识点整理

介绍

本文以备忘录应用为示例,介绍如何在实现标题展开时继续下拉的动效。

效果图预览

使用说明

  1. 进入页面,起初标题并没有展开,与增加/分享的菜单在同一行。
  2. 进行第一次下拉操作,此时标题展开至目标位置,并显示笔记数目信息,与菜单不在同一行。
  3. 继续下拉,达到阈值距离后,标题与菜单都下拉一段距离,并放大;松手后回弹至第一次下拉后的状态。
  4. 向上滑动,标题折叠,回到初始时的状态。

实现思路

  1. 标题是否展开,通过状态变量isExpanded控制,展开后原先标题置空,将展开后标题设置为可见。
   Column() {
   
   
     Row() {
   
   
       Text(!this.isExpanded ? $r('app.string.expanded_title_memo_title') : '') // 展开前的标题
         .fontSize($r('app.string.expanded_title_init_title_font_size'))
       ......
     }
     .width($r('app.string.expanded_title_layout_100_percent'))
     .padding($r('app.string.expanded_title_layout_25'))
     .margin({
   
    top: $r('app.string.expanded_title_layout_10') })
     .alignItems(VerticalAlign.Center)
     .translate(this.getMenuTranslateOptions())
     .animation({
   
    duration: this.duration, curve: Curve.FastOutLinearIn })
   
     if (this.isExpanded) {
   
    // 展开后的标题
       Column() {
   
   
         Text($r('app.string.expanded_title_memo_title'))
           .fontSize($r('app.string.expanded_title_font_size'))
         Text($r('app.string.expanded_title_memo_counts'))
           .fontSize($r('app.string.expanded_title_memo_counts_font_size'))
           .fontColor(Color.Grey)
       }
       .width(<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值