属性动画 进阶(ObjectAnimator)
2017-02-27 14:49
162 查看
首先
这不是一篇介绍属性动画使用的文章,如何使用网上一大把,不愿意做别人做过的事情。正文
我在看了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); //移动xy Path 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!欢淫吐槽,指正,评论!相关文章推荐
- Android属性动画完全解析(二)-ValueAnimator和ObjectAnimator的高级用法
- Android属性动画,ValueAnimator和ObjectAnimator的高级用法
- (二)属性动画一重境界之ObjectAnimator
- Android属性动画完全解析(中),ValueAnimator和ObjectAnimator的高级用法
- fragment设置关于translationY属性的objectAnimator属性动画
- 【转】android 属性动画之 ObjectAnimator
- 王学岗的属性动画上(二)——objectAnimator的非主流用法
- android 属性动画之 ObjectAnimator
- Android属性动画完全解析(中),ValueAnimator和ObjectAnimator的高级用法
- Android动画-属性动画-ObjectAnimator
- 属性动画05-ObjectAnimator的高级使用
- Android属性动画完全解析(中),ValueAnimator和ObjectAnimator的高级用法
- Android - ObjectAnimator set pivot value属性动画设置放大时的中心点设置
- Android属性动画完全解析(中),ValueAnimator和ObjectAnimator的高级用法
- Android属性动画完全解析(中),ValueAnimator和ObjectAnimator的高级用法
- Android属性动画完全解析(中),ValueAnimator和ObjectAnimator的高级用法
- Android属性动画完全解析(中),ValueAnimator和ObjectAnimator的高级用法
- Android属性动画完全解析(中),ValueAnimator和ObjectAnimator的高级用法
- Android属性动画完全解析(中),ValueAnimator和ObjectAnimator的高级用法
- Android属性动画的学习_ObjectAnimator