android動畫的簡單使用
AnimationSet set = new AnimationSet(false);//讓動畫隨自己設置
RotateAnimation rotate=new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setDuration(1000);//設置閃屏時間
rotate.setFillAfter(true);//保存當前動畫畫面
ScaleAnimation scale = new ScaleAnimation(0, 1, 0, 1,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
scale.setDuration(1000);// 動畫時間
scale.setFillAfter(true);// 保持動畫狀態
// 漸變動畫
AlphaAnimation alpha = new AlphaAnimation(0, 1);
alpha.setDuration(2000);// 動畫時間
alpha.setFillAfter(true);// 保持動畫狀態
set.addAnimation(rotate);
set.addAnimation(scale);
set.addAnimation(alpha);
sl_root.startAnimation(set);//sl_root爲動畫的線性佈局
如果想在動畫開始或結束時對activity進行操作,可以設置其監聽事件。
set.setAnimationListener(this);