animator 动画
动画的作用是让UI有动感, 看上去时尚。
Android中动画分两种方式:
一种方式是补间动画Tween Animation,就是说你定义一个开始和结束,中间的部分由程序运算得到。
另一种叫逐帧动画Frame Animation,就是说一帧一帧的连起来播放就变成了动画。
动画可以实现的效果:
1. 移动(Translation)
2. 透明度(alpha)
3. 旋转(rotate)
4. 缩放 (scale)
现在分别用例子来讲解:以下的实现都是用代码实现的(ObjectAnimator)
1. 移动(Translation)
主要代码[java]
AnimatorSet set = new AnimatorSet() ;
ObjectAnimator anim = ObjectAnimator .ofFloat(phone, "translationX", -500f, 0f);
anim.setDuration(2000);
ObjectAnimator anim3 = ObjectAnimator .ofFloat(phone, "translationX", 0f, -500f);
anim3.setDuration(2000);
ObjectAnimator anim2 = ObjectAnimator .ofFloat(phone, "translationY", 0f, -500f);
anim2.setDuration(2000);
ObjectAnimator anim4 = ObjectAnimator .ofFloat(phone, "translationY", -500f, 0f);
anim4.setDuration(2000);
AnimatorSet set3 = new AnimatorSet();
set3.play(anim4).before(anim3) ;
AnimatorSet set2 = new AnimatorSet();
set2.play(anim2).before(set3) ;
set.play(anim).before(set2);
set.start();
AnimatorSet set = new AnimatorSet() ;
ObjectAnimator anim = ObjectAnimator .ofFloat(phone, "translationX", -500f, 0f);
anim.setDuration(2000);
ObjectAnimator anim3 = ObjectAnimator .ofFloat(phone, "translationX", 0f, -500f);
anim3.setDuration(2000);
ObjectAnimator anim2 = ObjectAnimator .ofFloat(phone, "translationY", 0f, -500f);
anim2.setDuration(200