你好,游客 登录 注册 搜索
背景:
阅读新闻

Android开发之Animation 4种动画效果

[日期:2012-06-16] 来源:Linux社区  作者:baolong47 [字体:大 中 小]
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(1, 13, 10, 50);  //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 设置动画效果  
linux
相关资讯       Android编程开发 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款