当前位置: 首页 > news >正文

重庆网页设计美工渭南网站建设seo

重庆网页设计美工,渭南网站建设seo,网页设计制作作品,禹城网站建设电话一、背景介绍项目背景是在界面中弹出一个浮层动画#xff0c;同时播放一个音效。二、当前实现实现思路比较简单#xff1a;继承一个DialogFragment#xff0c;在相关的生命周期方法onViewCreated中调用startLottieAnim进行动画播放#xff0c;同时监听lottie动画播放的回调…一、背景介绍项目背景是在界面中弹出一个浮层动画同时播放一个音效。二、当前实现实现思路比较简单继承一个DialogFragment在相关的生命周期方法onViewCreated中调用startLottieAnim进行动画播放同时监听lottie动画播放的回调事件在动画开始播放时播放音效文件动画播放结束时关闭DialogFragment。1234567891011121314151617181920212223242526272829private void startLottieAnim(String assetFolder, final Uri voiceUri){lottieAnimationView.setImageAssetsFolder(assetFolder /images);lottieAnimationView.setAnimation(assetFolder /anim.json);lottieAnimationView.setRepeatCount(0);lottieAnimationView.addAnimatorListener(new Animator.AnimatorListener() {Overridepublic void onAnimationStart(Animator animation){playAnimVoice(voiceUri);}Overridepublic void onAnimationEnd(Animator animation){stopAnimVoice();dismiss();}Overridepublic void onAnimationCancel(Animator animation){stopAnimVoice();dismiss();}Overridepublic void onAnimationRepeat(Animator animation){playAnimVoice(voiceUri);}});lottieAnimationView.playAnimation();}三、发现问题对于以上的代码实际运行起来会发现动画播放的同时并不能播放音频而且播放结束也不会自动消失。也就是说onAnimationStart和onAnimationEnd方法并没有被回调。这是为什么呢看lottie实现源码 (BaseLottieAnimator)会发现123456789void notifyStart(boolean isReverse){for (Animator.AnimatorListener listener : listeners) {if (Build.VERSION.SDK_INT Build.VERSION_CODES.O) {listener.onAnimationStart(this, isReverse);} else {listener.onAnimationStart(this);}}}12345678void notifyEnd(boolean isReverse){for (Animator.AnimatorListener listener : listeners) {if (Build.VERSION.SDK_INT Build.VERSION_CODES.O) {listener.onAnimationEnd(this, isReverse);} else {listener.onAnimationEnd(this);}}在通知动画开始和结束的时候会根据系统版本决定走哪个方法这里需要注意方法签名。由于之前代码只写了一个参数的方法回调因此在Android O及以上版本中会走另一个方法回调。因此首先想到需要在注册的AnimatorListener中添加之前遗漏的两个方法回调。12345678910111213141516171819202122232425262728293031323334353637383940{lottieAnimationView.setImageAssetsFolder(assetFolder /images);lottieAnimationView.setAnimation(assetFolder /anim.json);lottieAnimationView.setRepeatCount(0);lottieAnimationView.addAnimatorListener(new Animator.AnimatorListener() {Overridepublic void onAnimationStart(Animator animation){playAnimVoice(voiceUri);}Overridepublic void onAnimationStart(Animator animation, boolean isReverse){playAnimVoice(voiceUri);}Overridepublic void onAnimationEnd(Animator animation){stopAnimVoice();dismiss();}Overridepublic void onAnimationEnd(Animator animation, boolean isReverse){stopAnimVoice();dismiss();}Overridepublic void onAnimationCancel(Animator animation){stopAnimVoice();dismiss();}Overridepublic void onAnimationRepeat(Animator animation){playAnimVoice(voiceUri);}});lottieAnimationView.playAnimation();}修改之后运行会发现动画播放结束的回调事件成功接收了但是音效依然无法播放。也就是onAnimationStart方法依然未被回调。继续看下源码在LottieAnimationView.java中12345678public void playAnimation(){if (isShown()) {lottieDrawable.playAnimation();enableOrDisableHardwareLayer();} else {wasAnimatingWhenNotShown true;}}如果isShown判断成功会继续走LottieDrawable.java中的123456789101112131415161718public void playAnimation(){if (compositionLayer null) {lazyCompositionTasks.add(new LazyCompositionTask() {Overridepublic void run(LottieComposition composition){playAnimation();}});return;}if (systemAnimationsEnabled || getRepeatCount() 0) {animator.playAnimation();}if (!systemAnimationsEnabled) {setFrame((int) (getSpeed() 0 ? getMinFrame() : getMaxFrame()));}}进而走到LottieValueAnimator.java中的playAnimation123456789MainThreadpublic void playAnimation(){running true;notifyStart(isReversed());setFrame((int) (isReversed() ? getMaxFrame() : getMinFrame()));lastFrameTimeNs 0;repeatCount 0;postFrameCallback();}在这里看到了熟悉的notifyStart方法。可是我们并没有收到对应的回调可以想到LottieAnimationView.java中并没有走isShown判断分支也就是说走了12345678public void playAnimation(){if (isShown()) {lottieDrawable.playAnimation();enableOrDisableHardwareLayer();} else {wasAnimatingWhenNotShown true;}}只是标记了一个状态标明lottie动画还未显示出来。那它为什么后来又能播放动画呢在LottieAnimationView.java中有监听可见性回调的方法12345678910111213141516171819protected void onVisibilityChanged(NonNull View changedView, int visibility){// This can happen on older versions of Android because onVisibilityChanged gets called from the// constructor of View so this will get called before lottieDrawable gets initialized.// https://github.com/airbnb/lottie-android/issues/1143if (lottieDrawable null) {return;}if (isShown()) {if (wasAnimatingWhenNotShown) {resumeAnimation();wasAnimatingWhenNotShown false;}} else {if (isAnimating()) {pauseAnimation();wasAnimatingWhenNotShown true;}}}当lottieview从不可见到可见时会根据wasAnimatingWhenNotShown之前记录的这个状态去resumeAnimation。在resumeAnimation方法一路跟下去最后会走到LottieValueAnimator.java的12345678910public void resumeAnimation(){running true;postFrameCallback();lastFrameTimeNs 0;if (isReversed() getFrame() getMinFrame()) {frame getMaxFrame();} else if (!isReversed() getFrame() getMaxFrame()) {frame getMinFrame();}}这里可以发现并没有像startAnimation那样的notifyXXX的回调方法了。因此我们收不到onAnimationStart的方法回调了。至此弄清楚了异常的原因如何修改就很简单了。现在已经能猜到是布局加载之后lottieview还没有渲染出来我们就去startAnimation导致回调无法走到因此我们可以通过对lottieView进行post或者通过监听viewTreeObserver的事件再进行startPlayAnimation操作就行了。四、总结1、回调方法要写完整2、如果弹框一开始就要显示lottie动画需要等ui控件可见之后再播放动画
http://www.pierceye.com/news/264182/

相关文章:

  • 深圳建设网站企业青白江做网站的公司
  • dm网站制作软件无忧网站建设
  • 如何在自己的网站上做歌单王建设医生网站
  • 科技+杭州+网站建设做效果图的网站有哪些
  • 引流推广网站平台wordpress页面发布失败
  • 南京哪家网站建设好网站开发需要注意的
  • 一个综合网站上线多少钱wordpress粘贴word
  • 承接电商网站建设新手做自己的网站
  • 网页版视频网站建设需要多少钱四川鸿业建设集团公司网站
  • h5网站实例wordpress改造mip
  • 完整的网络营销推广方案包括优化营商环境心得体会个人
  • 商洛市住房和城乡建设局网站建免费网站
  • 做网站要多少的服务器网站设计的步骤
  • 网站关键词怎么做上首页wordpress 架构原理
  • 厦门专业网站建设代理国外在线crm系统suitecrm
  • 哪个网站可以领手工活在家做wordpress heroku
  • 为什么没有网站做图文小说电子商务网站开发的课程介绍
  • 在哪个网站做问卷好单页面网站推广
  • 专业网站建设模块维护静海网站建设
  • 国内前十网站建设公司龙之网官网
  • 昆山做网站的公昆山做网站的公司司网站开发与设计岗位职责
  • 网站投注员怎么做做旅游项目用哪家网站好
  • 环县网站怎么做咸阳网站开发公司地址
  • 重庆巴南网站制作wordpress外贸建站公司
  • 桂林旅游网站制作公司软件开发公司属于什么行业
  • 网站 备案 中国 名字老薛主机 wordpress
  • 有什么网站可以做投票功能合肥房地产交易网
  • 世界网站广西建设工程质检安全网站
  • 建设银行网站会员基本信息wordpress主题图片丢失
  • 找人做网站需要注意什么问题中国建设信用卡网站