首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

android animator 动画片

2013-04-02 
android animator 动画animator 动画动画的作用是让UI有动感, 看上去时尚。Android中动画分两种方式:一种方

android animator 动画
animator 动画动画的作用是让UI有动感, 看上去时尚。
Android中动画分两种方式:
一种方式是补间动画Tween Animation,就是说你定义一个开始和结束,中间的部分由程序运算得到。另一种叫逐帧动画Frame Animation,就是说一帧一帧的连起来播放就变成了动画。

动画可以实现的效果: 1. 移动(Translation) 2. 透明度(alpha) 3. 旋转(rotate) 4. 缩放 (scale)
现在分别用例子来讲解:以下的实现都是用代码实现的(ObjectAnimator)
1. 移动(Translation)         主要代码

AnimatorSet set = new AnimatorSet() ;            ObjectAnimator anim = ObjectAnimator .ofFloat(phone, "scaleX", 1f);anim.setDuration(1000);ObjectAnimator anim2 = ObjectAnimator .ofFloat(phone, "scaleX", 0.5f);anim2.setDuration(1000);ObjectAnimator anim3 = ObjectAnimator .ofFloat(phone, "scaleY", 1f);anim3.setDuration(1000);ObjectAnimator anim4 = ObjectAnimator .ofFloat(phone, "scaleY", 0.5f);anim4.setDuration(1000);ObjectAnimator anim5 = ObjectAnimator .ofFloat(phone, "scaleX", 0.5f);anim5.setDuration(1000);ObjectAnimator anim6 = ObjectAnimator .ofFloat(phone, "scaleX",  1f);anim6.setDuration(1000);ObjectAnimator anim7 = ObjectAnimator .ofFloat(phone, "scaleY",0.5f);anim7.setDuration(1000);ObjectAnimator anim8 = ObjectAnimator .ofFloat(phone, "scaleY",  1f);anim8.setDuration(1000);AnimatorSet set3 = new AnimatorSet() ; set3.play(anim5).before(anim6);AnimatorSet set2 = new AnimatorSet() ;  set2.play(anim2).before(set3) ; AnimatorSet set4 = new AnimatorSet() ;  set4.play(anim7).before(anim8) ;AnimatorSet set5 = new AnimatorSet() ;  set5.play(anim4).before(set4);set.play(anim).before(set2);set.play(anim3).before(set5) ;set.start();




讲解:anim 从原来大小开始(X轴)
            anim2 缩放到原来的1/2(X轴)            anim3从原来大小开始(Y轴)
            anim4 缩放到原来的1/2(Y轴)
            anim5从原来的1/2开始放大(X轴)
            anim6放大到原来的大小(X轴)
            anim7从原来的1/2开始放大(Y轴)
            anim8放大到原来的大小(Y轴)

代码下载地址:http://download.csdn.net/detail/luhuajcdd/5191812

热点排行