android動畫的簡單使用

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);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章