Android开发之Animation 4种动画效果
Android开发之Animation 4种动画效果
Animation是Android的动画效果的组件,可以实现绚丽的翻页、ListView和GridView的展示。这blog简单介绍一下4种动画效果方式:
1. AlphaAnimation 控制渐变透明的动画效果 如图:
2. ScaleAnimation 控制尺寸伸缩的动画效果 如图:
3. TranslateAnimation 控制画面平移的动画效果 如图:
4. RotateAnimation 控制画面角度变化的动画效果 如图:
具体的使用方法,直接上代码。注:我演示的代码在activity的onCreate()方法里面,直接加载了ListView的动画效果
- AnimationSet set = new AnimationSet(false);
- Animation animation = new AlphaAnimation(0,1); //AlphaAnimation 控制渐变透明的动画效果
- animation.setDuration(500); //动画时间毫秒数
- set.addAnimation(animation); //加入动画集合
- animation = new TranslateAnimation(1, 13, 10, 50); //ScaleAnimation 控制尺寸伸缩的动画效果
- animation.setDuration(300);
- set.addAnimation(animation);
- animation = new RotateAnimation(30,10); //TranslateAnimation 控制画面平移的动画效果
- animation.setDuration(300);
- set.addAnimation(animation);
- animation = new ScaleAnimation(5,0,2,0); //RotateAnimation 控制画面角度变化的动画效果
- animation.setDuration(300);
- set.addAnimation(animation);
- LayoutAnimationController controller = new LayoutAnimationController(set, 1);
- GridView gridView = (GridView) this.findViewById(R.id.gridview);
- gridView .setLayoutAnimation(controller); //GridView 设置动画效果
- ListView listview= (ListView)this.findViewById(R.id.listview);
- listview.setLayoutAnimation(controller); //ListView 设置动画效果
评论暂时关闭