Android Animation一共有四種動畫
Alpha: 淡入淡出效果對象
Scale: 縮放效果get
Rotate: 旋轉效果io
Translate:移動效果class
使用Tweened Animations的步驟軟件
1.建立一個AnimationSet對象方法
2.根據須要建立須要的Animation對象im
3.根據軟件動畫的須要,爲Animation對象設置相應的數據數據
4.將Animation對象添加到AnimationSet對象中移動
5.使控件對象開始執行AnimationSet
Alpha動畫
AnimationSet as=new AnimationSet(true);
AlphaAnimation al=new AlphaAnimation(1,0);
//1表明徹底不透明,0表明徹底透明
al.setDuration(3000);
as.addAnimation(al);
iv.startAnimation(as);
AnimationSet as=new AnimationSet(true);
AlphaAnimation al=new AlphaAnimation(1,0);
//1表明徹底不透明,0表明徹底透明
al.setDuration(3000);
as.addAnimation(al);
iv.startAnimation(as);
Rotate動畫
AnimationSet as=new AnimationSet(true);
RotateAnimation al=new RotateAnimation (0,720,Animation.RELATIVE_TO_PARENT,0.5f,Animation.RELATIVE_TO_PARENT,0.5f);
//前兩個參數參數旋轉的角度,後面幾個參數決定旋轉的中心
//Animation.ABSOLUTE:絕對座標
//Animation.RELATIVE_TO_PARENT:相對父控件
//Animation.RELATIVE_TO_SELF:相對本身
al.setDuration(3000);
as.addAnimation(al);
iv.startAnimation(as);
AnimationSet as=new AnimationSet(true);
RotateAnimation al=new RotateAnimation (0,720,Animation.RELATIVE_TO_PARENT,0.5f,Animation.RELATIVE_TO_PARENT,0.5f);
//前兩個參數參數旋轉的角度,後面幾個參數決定旋轉的中心
//Animation.ABSOLUTE:絕對座標
//Animation.RELATIVE_TO_PARENT:相對父控件
//Animation.RELATIVE_TO_SELF:相對本身
al.setDuration(3000);
as.addAnimation(al);
iv.startAnimation(as);
Scale動畫
AnimationSet as=new AnimationSet(true);
ScaleAnimation al=new ScaleAnimation(0,1,0,1,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
//前四個參數是X從多大到多大,Y從多大到多大,後面的參數是縮放的中心點
al.setDuration(3000);
as.addAnimation(al);
iv.startAnimation(as);
AnimationSet as=new AnimationSet(true);
ScaleAnimation al=new ScaleAnimation(0,1,0,1,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
//前四個參數是X從多大到多大,Y從多大到多大,後面的參數是縮放的中心點
al.setDuration(3000);
as.addAnimation(al);
iv.startAnimation(as);
Translate動畫
AnimationSet as=new AnimationSet(true);
TranslateAnimation al=new TranslateAnimation(Animation.RELATIVE_TO_SELF,0,Animation.RELATIVE_TO_SELF,2,Animation.RELATIVE_TO_SELF,0,Animation.RELATIVE_TO_SELF,2);
al.setDuration(3000);
as.addAnimation(al);
iv.startAnimation(as);
AnimationSet as=new AnimationSet(true);
TranslateAnimation al=new TranslateAnimation(Animation.RELATIVE_TO_SELF,0,Animation.RELATIVE_TO_SELF,2,Animation.RELATIVE_TO_SELF,0,Animation.RELATIVE_TO_SELF,2);
al.setDuration(3000);
as.addAnimation(al);
iv.startAnimation(as);
Animation還有幾個方法
setFillAfter(boolean fillAfter)
若是fillAfter的值爲真的話,動畫結束後,控件停留在執行後的狀態
setFillBefore(boolean fillBefore)
若是fillBefore的值爲真的話,動畫結束後,控件停留在動畫開始的狀態
setStartOffset(long startOffset)
設置動畫控件執行動畫以前等待的時間
setRepeatCount(int repeatCount)
設置動畫重複執行的次數