前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Android高级动画(4)完结篇目录回顾封装库总结

Android高级动画(4)完结篇目录回顾封装库总结

作者头像
大公爵
发布2018-09-05 17:25:21
8110
发布2018-09-05 17:25:21
举报
文章被收录于专栏:葬爱家族葬爱家族

目录

Android高级动画(1)http://www.jianshu.com/p/48554844a2db

Android高级动画(2)http://www.jianshu.com/p/89cfd9042b1e

Android高级动画(3)http://www.jianshu.com/p/d6cc8d218900

Android高级动画(4)http://www.jianshu.com/p/91f8363c3a8c

回顾

终于到了完结篇,简单对前面三篇做个总结。Android系统为我们提供了丰富的动画, 罗列如下:

Tween动画,属性动画,Frame动画,CircularReveal,Activity转场动画,5.0转场动画又分为Explode、Slide、Alpha、ShareElements,矢量动画,矢量动画分为pathMorphing、trimPath。为了弥补一矢量动画不能代码动态构建的缺点,我们自己封装了PathMorphingView和TrimPathView。对于复杂图形,我们不能手动计算路径的,可以使用GIMP、Illustrator这样的工具,但是这些工具生成path不可控,于是自己开发了PathController。

封装库

为了简化动画的使用,我尝试封装了一个简单的库,包含所有常用的动画,可以用最简单的链式调用实现各种动画。下面简单地举几个例子:

(1)对比写法

传统写法:

代码语言:javascript
复制
ImageView img = (ImageView )findViewById(R.id.img);
ObjectAnimator animator = ObjectAnimator.ofFloat(sectorView, "translationY", 0, 100);
animator.setDuration(1000);
animator.setRepeatCount(1);
animator.setRepeatMode(ValueAnimator.RESTART);
animator .start();

使用库写法:

代码语言:javascript
复制
CommonAnimator.translateY(img, 0, 100)
        .duration(1000)
        .repeat(ValueAnimator.RESTART, ValueAnimator.RESTART)
        .start();

链式调用的写法是不是看起来更清爽,更简洁呢。

(2)再看个旋转动画

代码语言:javascript
复制
CommonAnimator.rotateY(img, 0, 360)
        .duration(1000)
        .repeat(ValueAnimator.INFINITE, ValueAnimator.REVERSE)
        .decelerate()
        .start();

(3)再看个同步动画

代码语言:javascript
复制
CommonAnimator.playTogether(
        CommonAnimator.translateX(img, 0, 400),
        CommonAnimator.rotateY(img, 0, 360)
).duration(1000).start();

是不是超简洁,超清晰

(4)再看个序列动画

代码语言:javascript
复制
CommonAnimator.playSequentially(
        CommonAnimator.translateX(img, 0, 400),
        CommonAnimator.rotateY(img, 0, 360)
).duration(1000).start();

(5)再来看个frame动画

代码语言:javascript
复制
CommonAnimator.animateFrame(img, animatinResId).start();

也可以单独设置图片id和时间

代码语言:javascript
复制
int[] resIdArray = getRes();
int[] times = getTimes();
CommonAnimator.animateFrame(img, resIdArray, times).start();

也可以一帧一帧添加

代码语言:javascript
复制
CommonAnimator.animateFrame(img)
    .addFrame(R.mipmap.head_image_01, 100)
    .addFrame(R.mipmap.head_image_02, 100)
    .addFrame(R.mipmap.head_image_03, 100)
    .addFrame(R.mipmap.head_image_04, 100)
    .start();

// 或者传drawable
CommonAnimator.animateFrame(img)
    .addFrame(drawable1, 100)
    .addFrame(drawable2, 100)
    .addFrame(drawable3, 100)
    .addFrame(drawable4, 100)
    .start();

(6)再来看个path动画

代码语言:javascript
复制
CommonAnimator.animatePath(img, path)
        .duration(1000)
        .start();

(7)再来看个CircularReveal

代码语言:javascript
复制
CommonAnimator.circularReveal(img, img.getWidth() / 2, img.getHeight() / 2, 0, img.getWidth() / 2)
    .decelerate()
    .start();

同时这个库也包含了之前封装的适量动画的View,使用方法参考demo。

吃瓜群众

总结

看到这里,恭喜你终于看完了。但是事实上,动画这个话题是没有尽头的,各种新的效果在不断地设计出来,我们封装再多框架也不可能一劳永逸,唯有理解了每一种动画的本质,才能以不变应万变。最后说句题外话,移动开发到这个程度如果还有人认为动画不重要,那就不可挽救了。现在的App市场竞争这么激烈,除了功能强大之外,用户体验的要求也是越来越高,如果我们的App能有一些惊艳的动画,能有一些酷炫的交互效果,那对于提升用户体验是很有帮助的。

由于个人水平有限,四篇文章中难免会有错误和不当之处,如有发现,请在评论处留言,给予指正。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017.07.05 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 目录
  • 回顾
  • 封装库
    • (1)对比写法
      • (2)再看个旋转动画
        • (3)再看个同步动画
          • (4)再看个序列动画
            • (5)再来看个frame动画
              • (6)再来看个path动画
                • (7)再来看个CircularReveal
                • 总结
                领券
                问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档