Android开发之Animation 4种动画效果


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.   
  6. animation = new TranslateAnimation(1131050);  //ScaleAnimation 控制尺寸伸缩的动画效果   
  7. animation.setDuration(300);  
  8. set.addAnimation(animation);  
  9.   
  10. animation = new RotateAnimation(30,10);    //TranslateAnimation  控制画面平移的动画效果   
  11. animation.setDuration(300);  
  12. set.addAnimation(animation);  
  13.   
  14. animation = new ScaleAnimation(5,0,2,0);    //RotateAnimation  控制画面角度变化的动画效果   
  15. animation.setDuration(300);  
  16. set.addAnimation(animation);  
  17.   
  18. LayoutAnimationController controller = new LayoutAnimationController(set, 1);  
  19.   
  20.   
  21. GridView gridView = (GridView) this.findViewById(R.id.gridview);  
  22. gridView .setLayoutAnimation(controller);  //GridView 设置动画效果   
  23.   
  24. ListView listview= (ListView)this.findViewById(R.id.listview);  
  25. listview.setLayoutAnimation(controller);   //ListView 设置动画效果  

相关内容