zoukankan      html  css  js  c++  java
  • 【转】android 属性动画之 ObjectAnimator

    原文网址:http://blog.csdn.net/feiduclear_up/article/details/39255083

    前面一篇博客讲解了 android 简单动画之 animtion,这里来讲解一下android 3.0之后添加的一些动画   animator 中的 ObjectAnimator 。

    属性动画概念:

    所谓属性动画:改变一切能改变的对象的属性值,不同于补间动画:只能改变 alpha,scale,rotate,translate。听着有点抽象,举例子说明
     

    补间动画能实现的:

    1.alpha 

    [java] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. //第一个参数为 view对象,第二个参数为 动画改变的类型,第三,第四个参数依次是开始透明度和结束透明度。  
    2.         ObjectAnimator alpha = ObjectAnimator.ofFloat(text, "alpha", 0f, 1f);  
    3.         alpha.setDuration(2000);//设置动画时间  
    4.         alpha.setInterpolator(new DecelerateInterpolator());//设置动画插入器,减速  
    5.         alpha.setRepeatCount(-1);//设置动画重复次数,这里-1代表无限  
    6.         alpha.setRepeatMode(Animation.REVERSE);//设置动画循环模式。  
    7.         alpha.start();//启动动画。  


    2.scale

    [java] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. AnimatorSet animatorSet = new AnimatorSet();//组合动画  
    2.         ObjectAnimator scaleX = ObjectAnimator.ofFloat(text, "scaleX", 1f, 0f);  
    3.         ObjectAnimator scaleY = ObjectAnimator.ofFloat(text, "scaleY", 1f, 0f);  
    4.   
    5.         animatorSet.setDuration(2000);  
    6.         animatorSet.setInterpolator(new DecelerateInterpolator());  
    7.         animatorSet.play(scaleX).with(scaleY);//两个动画同时开始  
    8.         animatorSet.start();  


    3.translate

    [java] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. ObjectAnimator translationUp = ObjectAnimator.ofFloat(button, "Y",  
    2.                 button.getY(), 0);  
    3.         translationUp.setInterpolator(new DecelerateInterpolator());  
    4.         translationUp.setDuration(1500);  
    5.         translationUp.start();  


    4. rotate

    [java] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. AnimatorSet set = new AnimatorSet() ;               
    2.      ObjectAnimator anim = ObjectAnimator .ofFloat(phone, "rotationX", 0f, 180f);   
    3.      anim.setDuration(2000);   
    4.      ObjectAnimator anim2 = ObjectAnimator .ofFloat(phone, "rotationX", 180f, 0f);   
    5.      anim2.setDuration(2000);   
    6.      ObjectAnimator anim3 = ObjectAnimator .ofFloat(phone, "rotationY", 0f, 180f);   
    7.      anim3.setDuration(2000);   
    8.      ObjectAnimator anim4 = ObjectAnimator .ofFloat(phone, "rotationY", 180f, 0f);   
    9.      anim4.setDuration(2000);   
    10.         
    11.      set.play(anim).before(anim2); //先执行anim动画之后在执行anim2  
    12.      set.play(anim3).before(anim4) ;   
    13.      set.start();   

    补间动画不能实现的:

    5.android 改变背景颜色的动画实现如下

    [java] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. ObjectAnimator translationUp = ObjectAnimator.ofInt(button,  
    2.                 "backgroundColor", Color.RED, Color.BLUE, Color.GRAY,  
    3.                 Color.GREEN);  
    4.         translationUp.setInterpolator(new DecelerateInterpolator());  
    5.         translationUp.setDuration(1500);  
    6.         translationUp.setRepeatCount(-1);  
    7.         translationUp.setRepeatMode(Animation.REVERSE);  
    8.         /* 
    9.          * ArgbEvaluator:这种评估者可以用来执行类型之间的插值整数值代表ARGB颜色。 
    10.          * FloatEvaluator:这种评估者可以用来执行浮点值之间的插值。 
    11.          * IntEvaluator:这种评估者可以用来执行类型int值之间的插值。 
    12.          * RectEvaluator:这种评估者可以用来执行类型之间的插值矩形值。 
    13.          *  
    14.          * 由于本例是改变View的backgroundColor属性的背景颜色所以此处使用ArgbEvaluator 
    15.          */  
    16.   
    17.         translationUp.setEvaluator(new ArgbEvaluator());  
    18.         translationUp.start();  



    更多关于android 属性动画的相关知识请参考详细博客 Android属性动画Property Animation系列一之ValueAnimator

  • 相关阅读:
    Tomcat集群Cluster实现原理剖析[转] 文件同步
    看到一个比较好的jbpm教程,感谢一下
    vi显示行号
    安装apache2参数详解
    Windows平台下查看占用端口的程序
    struts2中使用token避免重复提交
    在window下安装开源的中文界面的项目管理软件Redmine
    Java中数据存储
    求素数算法网摘
    模式工程化实现及扩展读书笔记——设计原则
  • 原文地址:https://www.cnblogs.com/wi100sh/p/5803989.html
Copyright © 2011-2022 走看看