• Android視頻教程AlphaAnimation詳解

    0
    常見的android視頻教程中經常會提到如下4種動畫效果: 

    1、AlphaAnimation 透明度動畫效果 
    2、ScaleAnimation 縮放動畫效果 
    3、TranslateAnimation 位移動畫效果 
    4、RotateAnimation 旋轉動畫效果 

    這4種效果是當今android開發的主流手段,一般大型的android開發項目中都會用到。對于android初學者來說,必須要牢牢掌握這4種效果。今天主要講解AlphaAnimation透明度動畫效果的實現方法。常用于窗口動畫效果、LOGO淡入淡出的實現。

    android開發 AlphaAnimation代碼示例:
    1. public class MainActivity extends Activity { 
    2. ImageView image; 
    3. Button start; 
    4. Button cancel; 
    5. @Override 
    6. public void onCreate(Bundle savedInstanceState) { 
    7. super.onCreate(savedInstanceState); 
    8. setContentView(R.layout.activity_main); 
    9. image = (ImageView) findViewById(R.id.main_img); 
    10. start = (Button) findViewById(R.id.main_start); 
    11. cancel = (Button) findViewById(R.id.main_cancel); 
    12. /** 設置透明度漸變動畫 */ 
    13. final AlphaAnimation animation = new AlphaAnimation(1, 0); 
    14. animation.setDuration(2000);//設置動畫持續時間 
    15. /** 常用方法 */ 
    16. //animation.setRepeatCount(int repeatCount);//設置重復次數 
    17. //animation.setFillAfter(boolean);//動畫執行完后是否停留在執行完的狀態 
    18. //animation.setStartOffset(long startOffset);//執行前的等待時間 
    19. start.setOnClickListener(new OnClickListener() { 
    20. public void onClick(View arg0) { 
    21. image.setAnimation(animation); 
    22. /** 開始動畫 */ 
    23. animation.startNow(); 

    24. }); 
    25. cancel.setOnClickListener(new OnClickListener() { 
    26. public void onClick(View v) { 
    27. /** 結束動畫 */ 
    28. animation.cancel(); 

    29. }); 

    30. }

    相似問題

    相關經驗

    相關資訊

    相關文檔

  • sesese色