android 3.0之后添加的一些动画 animator 中的 ObjectAnimator:
补间动画能实现的:
1.alpha 透明度
//第一个参数为 view对象,第二个参数为 动画改变的类型,第三,第四个参数依次是开始透明度和结束透明度。
ObjectAnimator alpha = ObjectAnimator.ofFloat(text, "alpha", 0f, 1f);
alpha.setDuration(2000);//设置动画时间
alpha.setInterpolator(new DecelerateInterpolator());//设置动画插入器,减速
alpha.setRepeatCount(-1);//设置动画重复次数,这里-1代表无限
alpha.setRepeatMode(Animation.REVERSE);//设置动画循环模式。
alpha.start();//启动动画。
2.scale
AnimatorSet animatorSet = new AnimatorSet();//组合动画
ObjectAnimator scaleX = ObjectAnimator.ofFloat(text, "scaleX", 1f, 0f);
ObjectAnimator scaleY = ObjectAnimator.ofFloat(text, "scaleY", 1f, 0f);
animatorSet.setDuration(2000);
animatorSet.setInterpolator(new DecelerateInterpolator());
animatorSet.play(scaleX).with(scaleY);//两个动画同时开始
animatorSet.start();
3.translate
ObjectAnimator translationUp = ObjectAnimator.ofFloat(button, "Y",button.getY(), 0);
translationUp.setInterpolator(new DecelerateInterpolator());
translationUp.setDuration(1500);
translationUp.start();
4. rotate
AnimatorSet set = new AnimatorSet() ;
ObjectAnimator anim = ObjectAnimator .ofFloat(phone, "rotationX", 0f, 180f);
anim.setDuration(2000);
ObjectAnimator anim2 = ObjectAnimator .ofFloat(phone, "rotationX", 180f, 0f);
anim2.setDuration(2000);
ObjectAnimator anim3 = ObjectAnimator .ofFloat(phone, "rotationY", 0f, 180f);
anim3.setDuration(2000);
ObjectAnimator anim4 = ObjectAnimator .ofFloat(phone, "rotationY", 180f, 0f);
anim4.setDuration(2000);
set.play(anim).before(anim2); //先执行anim动画之后在执行anim2
set.play(anim3).before(anim4) ;
set.start();
补间动画不能实现的:
5.android 改变背景颜色的动画实现如下
ObjectAnimator translationUp = ObjectAnimator.ofInt(button,
"backgroundColor", Color.RED, Color.BLUE, Color.GRAY,
Color.GREEN);
translationUp.setInterpolator(new DecelerateInterpolator());
translationUp.setDuration(1500);
translationUp.setRepeatCount(-1);
translationUp.setRepeatMode(Animation.REVERSE);
/*
* ArgbEvaluator:这种评估者可以用来执行类型之间的插值整数值代表ARGB颜色。
* FloatEvaluator:这种评估者可以用来执行浮点值之间的插值。
* IntEvaluator:这种评估者可以用来执行类型int值之间的插值。
* RectEvaluator:这种评估者可以用来执行类型之间的插值矩形值。
*
* 由于本例是改变View的backgroundColor属性的背景颜色所以此处使用ArgbEvaluator
*/
translationUp.setEvaluator(new ArgbEvaluator());
translationUp.start();
关于Animation更详细的教程:
Android属性动画Property Animation系列一之ValueAnimator:
http://blog.csdn.net/feiduclear_up/article/details/45893619
Android属性动画Property Animation系列二之ObjectAnimator
http://blog.csdn.net/feiduclear_up/article/details/45915377
来源:oschina
链接:https://my.oschina.net/u/2242731/blog/493268