Android 动画 之 ObjectAnimator

android 3.0以后添加的一些动画   animator 中的 ObjectAnimator java


补间动画能实现的:

1.alpha 透明度
android

//第一个参数为 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 lua


ObjectAnimator translationUp = ObjectAnimator.ofFloat(button, "Y",button.getY(), 0);
	translationUp.setInterpolator(new DecelerateInterpolator());
	translationUp.setDuration(1500);
	translationUp.start();



4. rotate spa

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 改变背景颜色的动画实现以下 .net

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更详细的教程: code

 Android属性动画Property Animation系列一之ValueAnimator: 对象

http://blog.csdn.net/feiduclear_up/article/details/45893619 blog


 Android属性动画Property Animation系列二之ObjectAnimator 教程

http://blog.csdn.net/feiduclear_up/article/details/45915377

相关文章
相关标签/搜索