android 属性动画之 ObjectAnimator

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

属性动画概念:

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

补间动画能实现的:

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();


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

 



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值