在Android3.0之前,andorid提供了几种动画类型 ViewAnimation,Drawable Animation,Property Ainmation,
View Animation相当简单,不过只能支持简单的缩放,平移,旋转,透明度这些基本的动画
Google在Android3.0之后,提供了属性动画,这使得动画系统变得极其强大了起来,考虑到很多app需要兼容3.0一下设备,特提供了一个动画库,Nineoldanimations
属性动画的基本使用:
1. 使一个控件在一定的时间里改变其背景颜色并且能够反复循环和反转的效果
TextView text=(TextView)findViewById(R.id.text);
ValueAnimatoranimator= ObjectAnimator.ofInt(text,"backgroundColor",0xffff8080,0xff8080ff);
animator.setDuration(3000);
animator.setEvaluator(new ArgbEvaluator());
animator.setRepeatCount(ValueAnimator.INFINITE);
animator.setRepeatMode(ValueAnimator.REVERSE);
animator.start();
2. 动画集合,5秒时间内,对view进行旋转,平移,缩放和透明度进行改变
AnimatorSet set = new AnimatorSet();
set.playTogether(ObjectAnimator.ofFloat(text, "rotationX",0,360)
,ObjectAnimator.ofFloat(text, "rotatioY",0,180)
,ObjectAnimator.ofFloat(text, "rotatio",0,-90)
,ObjectAnimator.ofFloat(text, "translationX",0,90)
,ObjectAnimator.ofFloat(text, "translationY",0,90)
,ObjectAnimator.ofFloat(text, "scaleX",1,1.5f)
,ObjectAnimator.ofFloat(text, "scaleY",1,0.5f)
,ObjectAnimator.ofFloat(text, "alpha",1,0.25f,1)
);
set.setDuration(5*1000).start();
在使用时需要注意前面的String类型的名字,需要正确,否则没有效果,这里只列举两种情况!