属性动画 进阶(ObjectAnimator)
来源:互联网 发布:牛鞭效应知乎 编辑:程序博客网 时间:2024/06/16 11:30
首先
这不是一篇介绍属性动画使用的文章,如何使用网上一大把,不愿意做别人做过的事情。
正文
我在看了N多介绍属性动画的文章后,发现所有千篇一律,诸如以下代码(请关注第二个参数属性名)
ObjectAnimator animator = ObjectAnimator.ofFloat(textview, "alpha", 1f, 0f, 1f); animator.setDuration(5000); animator.start(); ...ObjectAnimator animator = ObjectAnimator.ofFloat(textview, "rotation", 0f, 360f); animator.setDuration(5000); animator.start(); ...ObjectAnimator animator = ObjectAnimator.ofFloat(textview, "translationX", 0f, 360f); animator.setDuration(5000); animator.start(); ...ObjectAnimator animator = ObjectAnimator.ofFloat(textview, "translationY", 0f, 360f); animator.setDuration(5000); animator.start();
我很疑惑的是,难道我大google设计API,设计成这样?需要开发者记住每一个属性名吗,需要实现一个动画的时候,还需要先去想,这个属性的全拼是怎么样的,实在太扯淡。
观察ObjectAnimator方法之后发现以下方法
ofInt(T target, Property<T, Integer> property, int... values)ofInt(T target, Property<T, Integer> xProperty,Property<T, Integer> yProperty, Path path)ofFloat(T target, Property<T, Float> property, float... values)ofFloat(T target, Property<T, Float> xProperty,Property<T, Float> yProperty, Path path)...
其中第二个带xy属性的方法,Api21以上才有,使用起来veryEasy
//旋转ObjectAnimator animation = ObjectAnimator.ofFloat(fabIconStar, View.ROTATION, 0f, 45f);//ObjectAnimator animation = ObjectAnimator.ofFloat(fabIconStar,View.ROTATION, 0f, 45f,0f);//转回去ObjectAnimator animation = ObjectAnimator.ofFloat(tager, View.ROTATION, 45f, 0);//移动xyPath path = new Path(); path.lineTo(10, 10); path.lineTo(50, 20); //path.lineTo(10,10); //path.lineTo(0,0); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { ObjectAnimator animation1 = ObjectAnimator.ofFloat(tager, View.TRANSLATION_X,View.TRANSLATION_Y, path); animation1.start(); }//移动回去 Path path = new Path(); path.moveTo(50, 20); path.lineTo(10, 10); path.lineTo(0, 0); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { ObjectAnimator animation1 = ObjectAnimator.ofFloat(tager, View.TRANSLATION_X,View.TRANSLATION_Y, path); animation1.start(); }
可使用属性View内所有 Property 属性,
Property<View, Float> ...
有兴趣的可以一个个去尝试一下,在这里不作详述了。
谢谢
是不是soEasy!欢淫吐槽,指正,评论!
0 0
- 属性动画 进阶(ObjectAnimator)
- 属性动画(ObjectAnimator)源码分析
- 属性动画ObjectAnimator
- 属性动画之ObjectAnimator
- 属性动画之ObjectAnimator
- 属性动画ObjectAnimator
- Android动画-属性动画-ObjectAnimator
- android 动画 属性动画 ObjectAnimator
- android 属性动画之 ObjectAnimator
- 属性动画ValueAnimator和ObjectAnimator
- android 属性动画之 ObjectAnimator
- Android属性动画之ObjectAnimator
- android 属性动画之 ObjectAnimator
- android 属性动画之 ObjectAnimator
- android 属性动画之 ObjectAnimator
- android 属性动画之 ObjectAnimator
- Android 属性动画(二):ObjectAnimator与ValueAnimator
- Android属性动画系列(一)——ObjectAnimator
- 在POSIX系统中安装Redis
- 文章标题
- Intellij IDEA 2016.3.4 激活,注册
- 一键解决 502 Read from server failed: Unknown error
- 近 100 个 Linux 常用命令大全
- 属性动画 进阶(ObjectAnimator)
- html之marquee
- 欢迎使用CSDN-markdown编辑器
- HttpClient与HttpURLConnection网络请求工具类
- dao层和service层的区别
- 运维常用进程查看命令
- Linux shell变量
- 完全二叉树判断
- okhttp的interceptor拦截器功能