博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
android Animation 动画绘制逻辑
阅读量:7090 次
发布时间:2019-06-28

本文共 2540 字,大约阅读时间需要 8 分钟。

 

参考:http://www.jianshu.com/p/3683a69c38ea

 

 
1、View.draw(Canvas) 其中步骤为: /*  * Draw traversal performs several drawing steps which must be executed  * in the appropriate order:  *  *      1. Draw the background  *      2. If necessary, save the canvas' layers to prepare for fading  *      3. Draw view's content  *      4. Draw children  *      5. If necessary, draw the fading edges and restore layers  *      6. Draw decorations (scrollbars for instance)  */
2、ViewGroup.dispatchDraw(Canvas);如果控件为ViewGroup或者其子类,需要绘制子类 
3、ViewGroup.drawChild(Canvas canvas, View child, long drawingtime) 4、View.draw(Canvas canvas, ViewGroup parent, long drawingTime); 这个方法里面实现动画
  // 如下代码段获取Animation的矩阵、alipa等值   if (a != null) {
   more = applyLegacyAnimation(parent, drawingTime, a, scalingRequired);    concatMatrix = a.willChangeTransformationMatrix();    if (concatMatrix) {
   mPrivateFlags3 |= PFLAG3_VIEW_IS_ANIMATING_TRANSFORM;    }    transformToApply = parent.getChildTransformation();   } // 主要方法为 applyLegacyAnimation,其代码段
  final Transformation t = parent.getChildTransformation(); // 取出父控件保存的Transformation 对象   boolean more = a.getTransformation(drawingTime, t, 1f); // 用animation中的矩阵变化值填充 对象t; 其中a为程序员设置的动画对象      // Animation 的 getTransformation代码段
  final float interpolatedTime = mInterpolator.getInterpolation(normalizedTime);   applyTransformation(interpolatedTime, outTransformation); // 具体填充传入参数Transformation的方法,它是一个空方法,具体实现由子类负责   //例如:RotateAnimation 的 applyTransformation 方法,其中代码段:
  float degrees = mFromDegrees + ((mToDegrees - mFromDegrees) * interpolatedTime);   float scale = getScaleFactor();   if (mPivotX == 0.0f && mPivotY == 0.0f) {
   t.getMatrix().setRotate(degrees);   } else {
   t.getMatrix().setRotate(degrees, mPivotX * scale, mPivotY * scale); // 将旋转角度设置到transformation的矩阵中,其他子类也是相似逻辑   }
// View.draw( , , )真正实现动画的代码段:
  canvas.translate(-transX, -transY);   canvas.concat(transformToApply.getMatrix()); // 将从动画中取出的矩阵,传递给canvas实现动画效果   canvas.translate(transX, transY);   // View.draw(, ,)关键代码段:
  // Fast path for layouts with no backgrounds   if ((mPrivateFlags & PFLAG_SKIP_DRAW) == PFLAG_SKIP_DRAW) {
   mPrivateFlags &= ~PFLAG_DIRTY_MASK;    dispatchDraw(canvas); //   } else {
   draw(canvas);// 执行动画变换之后,接着绘制视图   }

 

结论: 1、Animation 动画中起关键作用的类是Transformation, animation负责计算动画的矩阵变换,Transformation负责将变换传递给Canvas. 2、Animation 动画只是对Canvas做了矩阵变换,并没有修改其属性值,这是它和属性动画的最大区别。 3、Alpha值的修改也在draw方法中保存了图层,不影响属性值

 

转载于:https://www.cnblogs.com/lipeil/p/5821491.html

你可能感兴趣的文章
我的友情链接
查看>>
我的友情链接
查看>>
Python爬虫框架Scrapy学习笔记原创
查看>>
大数据时代怎么做
查看>>
java基本语法
查看>>
细说HTTP之上篇
查看>>
将Eclipse Maven项目 导入 IDEA 步骤 成功运行 已测试!~LC
查看>>
Exchange Server 2010的俩种版本比较
查看>>
asp.net 插入视频
查看>>
laravel中的表单请求类型和CSRF防护(六)
查看>>
有1000瓶水,其中有一瓶有毒,小白鼠只要尝一点带毒的水24小时后就会死亡,至少要多...
查看>>
我的友情链接
查看>>
监控指定文件所有机器的网络状况
查看>>
11、网络--Linux Bridge(网桥基础)
查看>>
监控apache脚本原理
查看>>
参观迅达云成观后感
查看>>
linux(ubuntu)查看硬件设备命令
查看>>
centos 上 GraphicsMagic安装笔记
查看>>
tomcat与resin
查看>>
android应用要搞起了
查看>>