歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android開發之Animation 4種動畫效果

Android開發之Animation 4種動畫效果

日期:2017/3/1 10:19:40   编辑:Linux編程
Animation是Android的動畫效果的組件,可以實現絢麗的翻頁、ListView和GridView的展示。

這blog簡單介紹一下4種動畫效果方式:

1. AlphaAnimation 控制漸變透明的動畫效果 如圖:


2. ScaleAnimation 控制尺寸伸縮的動畫效果 如圖:


3. TranslateAnimation 控制畫面平移的動畫效果 如圖:


4. RotateAnimation 控制畫面角度變化的動畫效果 如圖:

具體的使用方法,直接上代碼。注:我演示的代碼在activity的onCreate()方法裡面,直接加載了ListView的動畫效果

  1. AnimationSet set = new AnimationSet(false);
  2. Animation animation = new AlphaAnimation(0,1); //AlphaAnimation 控制漸變透明的動畫效果
  3. animation.setDuration(500); //動畫時間毫秒數
  4. set.addAnimation(animation); //加入動畫集合
  5. animation = new TranslateAnimation(1, 13, 10, 50); //ScaleAnimation 控制尺寸伸縮的動畫效果
  6. animation.setDuration(300);
  7. set.addAnimation(animation);
  8. animation = new RotateAnimation(30,10); //TranslateAnimation 控制畫面平移的動畫效果
  9. animation.setDuration(300);
  10. set.addAnimation(animation);
  11. animation = new ScaleAnimation(5,0,2,0); //RotateAnimation 控制畫面角度變化的動畫效果
  12. animation.setDuration(300);
  13. set.addAnimation(animation);
  14. LayoutAnimationController controller = new LayoutAnimationController(set, 1);
  15. GridView gridView = (GridView) this.findViewById(R.id.gridview);
  16. gridView .setLayoutAnimation(controller); //GridView 設置動畫效果
  17. ListView listview= (ListView)this.findViewById(R.id.listview);
  18. listview.setLayoutAnimation(controller); //ListView 設置動畫效果
Copyright © Linux教程網 All Rights Reserved