zoukankan      html  css  js  c++  java
  • Android开源框架:NineOldAndroid

    在android3.0以前的版本,要实现动画,一般是使用NineOldAndroid开源框架,之后,就可以直接使用android提供的animation API了。

    仔细看过此开源框架后,可看出此框架和系统的动画实现还有有区别的。主要但不仅仅一下几点:

    1. 计算每帧动画的流程:AnimationHandler,NineOldAndroid中是继承于Handler,在消息队列中不断的处理每帧动画的数据,而系统则是实现了Runnable接口,在线程中进行处理

       

     1 //NineOldAndroid
     2 private static class AnimationHandler extends Handler{
     3         public void handlerMessage(){
     4         ....
     5         sendEmptyMessageDelayed(...);
     6         }
     7 
     8 
     9 //Android系统
    10 protected static class AnimationHandler implements Runnable {
    11         // The per-thread list of all active animations
    12         /** @hide */
    13         protected final ArrayList<ValueAnimator> mAnimations = new ArrayList<ValueAnimator>();
    14 
    15         // Used in doAnimationFrame() to avoid concurrent modifications of mAnimations
    16         private final ArrayList<ValueAnimator> mTmpAnimations = new ArrayList<ValueAnimator>();
    17 
    18         // The per-thread set of animations to be started on the next animation frame
    19         /** @hide */
    20         protected final ArrayList<ValueAnimator> mPendingAnimations = new ArrayList<ValueAnimator>();
    21 
    22         /**
    23          * Internal per-thread collections used to avoid set collisions as animations start and end
    24          * while being processed.
    25          * @hide
    26          */
    27         protected final ArrayList<ValueAnimator> mDelayedAnims = new ArrayList<ValueAnimator>();
    28         private final ArrayList<ValueAnimator> mEndingAnims = new ArrayList<ValueAnimator>();
    29         private final ArrayList<ValueAnimator> mReadyAnims = new ArrayList<ValueAnimator>();
    30 
    31         private final Choreographer mChoreographer;
    32         .....
    33         }
    View Code

    2. Choreographer:不同于开源框架中,android系统还新引入了Choreographer(编舞者),通过此类来协调动画时间,及绘制等。最主要的是Choreographer中提供了VSync:垂直中断。

    Choreographer会协调每帧时间,使用回调函数来执行Runnable.run。可使动画的显示更流畅,不会出现动画卡顿,画面撕裂等状况。关于VSync的一些更具体的知识可以百度。

  • 相关阅读:
    C# 调试
    C#添加资源的两种方式
    C# 光标文件的创建
    窗体初始位置
    C# 实现关闭按钮隐藏窗体而不退出
    mac ssd开启trim模式
    iOS打包上传app store各种问题解决总结
    adhoc无法下载应用程序 此时无法安装-解决
    debug1: expecting SSH2_MSG_KEX_ECDH_REPLY解决
    Could not load OpenSSL解决
  • 原文地址:https://www.cnblogs.com/luow/p/4511431.html
Copyright © 2011-2022 走看看