2024年鸿蒙最新HarmonyOS NEXT自定义视图实现Tab效果(2),2024年最新阿里、百度、美团、携程、蚂蚁面经分享

img
img

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

实现思路
  1. 页签实现:添加onClick方法,记录点击的index,index变化后,改变页签颜色、字体大小,使用animateTo方法实现页签切换动画。 源码参考CustomView.ets
Text(title)
  .textAlign(TextAlign.Center)
  .height($r('app.integer.width_and_height_value4'))
  .width(this.titleLengthRadix3 * title.length)
  .fontColor(this.currentIndex == idx ?
            (this.wantGoIndex == idx ? $r('app.color.background_color1'):$r('app.color.background_color2')):
            (this.wantGoIndex == idx ? $r('app.color.background_color1'):$r('app.color.background_color2')))
  .fontSize(this.currentIndex == idx ? $r('app.integer.font_size2') : $r('app.integer.font_size1'))
  .fontWeight(this.currentIndex == idx ? FontWeight.Bold : FontWeight.Normal)
  .onClick(() => {
    if (this.currentIndex != idx) {
      // 记录点击index
      this.wantGoIndex = idx;
      // 动画效果
      animateTo({
        duration: Math.abs(idx - this.currentIndex) * this.durationRadix,
        curve: Curve.EaseInOut,
        iterations: this.iterationsDefault,
        playMode: PlayMode.Normal,
        onFinish: () => {
          this.currentIndex = idx;
          this.scroller.scrollToIndex(this.currentIndex, true, ScrollAlign.START);
        }
      }, () => {
        this.transitionX = this.getTransitionX(idx);
      })
    }
  })
  1. 内容区实现:使用List,添加滑动手势来进行页面的切换,手势响应后,使用scrollToIndex方法来实现平滑的滑动到相应index。 源码参考CustomView.ets
PanGesture(this.panOption)
  .onActionUpdate((event:GestureEvent) => {
    if (!this.isStartAction) {
      this.isStartAction = true;
      if (event.offsetX < this.judgmentValue) {
        if (this.currentIndex < this.titleArray.length - this.currentIndexRadix) {
          let temIndex: number = this.currentIndex + this.currentIndexRadix;
          this.scroller.scrollToIndex(temIndex, true, ScrollAlign.START);
          this.wantGoIndex = temIndex;
          animateTo({
            duration: Math.abs(temIndex - this.currentIndex) * this.durationRadix,
            curve: Curve.EaseInOut,
            iterations: this.iterationsDefault,
            playMode: PlayMode.Normal,
            onFinish: () => {
              this.currentIndex = temIndex;
            }
          }, () => {
            this.transitionX = this.getTransitionX(temIndex);
          })
        }
      } else {
        if (this.currentIndex > this.judgmentValue) {
          let temIndex: number = this.currentIndex - this.currentIndexRadix;
          this.scroller.scrollToIndex(temIndex, true, ScrollAlign.START);
          this.wantGoIndex = temIndex;
          animateTo({
            duration: Math.abs(temIndex - this.currentIndex) * this.durationRadix,
            curve: Curve.EaseInOut,
            iterations: this.iterationsDefault,
            playMode: PlayMode.Normal,
            onFinish: () => {
              this.currentIndex = temIndex;
            }
          }, () => {
            this.transitionX = this.getTransitionX(temIndex);
          })
        }
      }
    }
  })
高性能知识点

scrollToIndex方法,开启smooth动效时,会对经过的所有item进行加载和布局计算,当大量加载item时会导致性能问题

工程结构&模块类型
customview                                       // har类型
|---view
|   |---CustomView.ets                           // 视图层-自定义视图实现Tab效果
模块依赖

utils

最后

有很多小伙伴不知道学习哪些鸿蒙开发技术?不知道需要重点掌握哪些鸿蒙应用开发知识点?而且学习时频繁踩坑,最终浪费大量时间。所以有一份实用的鸿蒙(HarmonyOS NEXT)资料用来跟着学习是非常有必要的。

这份鸿蒙(HarmonyOS NEXT)资料包含了鸿蒙开发必掌握的核心知识要点,内容包含了(**ArkTS、ArkUI开发组件、Stage模型、多端部署、分布式应用开发、音频、视频、WebGL、OpenHarmony****多媒体技术、Napi组件、OpenHarmony内核、Harmony南向开发、鸿蒙项目实战等等)鸿蒙(HarmonyOS NEXT)**技术知识点。

希望这一份鸿蒙学习资料能够给大家带来帮助,有需要的小伙伴自行领取,限时开源,先到先得~无套路领取!!

如果你是一名有经验的资深Android移动开发、Java开发、前端开发、对鸿蒙感兴趣以及转行人员,可以直接领取这份资料

获取这份完整版高清学习路线,请点击→纯血版全套鸿蒙HarmonyOS学习资料****

鸿蒙(HarmonyOS NEXT)最新学习路线

  • HarmonOS基础技能

  • HarmonOS就业必备技能 
  • HarmonOS多媒体技术

  • 鸿蒙NaPi组件进阶

  • HarmonOS高级技能

  • 初识HarmonOS内核
  • 实战就业级设备开发

img
img

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

正的技术提升。**

需要这份系统化的资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值