AnimationSet类是Android系统中的动画集合类,用于控制View对象进行多个动作的组合,该类继承于Animation类。AnimationSet类中的很多方法都与Animation类一致,该类中最常用的方法便是addAnimation方法,该方法用于为动画集合对象添加动画对象,可以为对象添加多个动画效果。

贴上android官方定义:

Class Overview

Represents a group of Animations that should be played together. The transformation of each individual animation are composed together into a single transform. If AnimationSet sets any properties that its children also set (for example, duration or fillBefore), the values of AnimationSet override the child values.

The way that AnimationSet inherits behavior from Animation is important to understand. Some of the Animation attributes applied to AnimationSet affect the AnimationSet itself, some are pushed down to the children, and some are ignored, as follows:

  • duration, repeatMode, fillBefore, fillAfter: These properties, when set on an AnimationSet object, will be pushed down to all child animations.
  • repeatCount, fillEnabled: These properties are ignored for AnimationSet.
  • startOffset, shareInterpolator: These properties apply to the AnimationSet itself.

Starting withICE_CREAM_SANDWICH, the behavior of these properties is the same in XML resources and at runtime (prior to that release, the values set in XML were ignored for AnimationSet). That is, callingsetDuration(500)on an AnimationSet has the same effect as declaringandroid:duration="500"in an XML resource for an AnimationSet object.

下面来实例演示以下AnimationSet的具体用法:

要求:点击界面上的按钮,按钮出现透明和转移的动画效果。

1.首先在界面上添加一个按钮,并配置其id和属性。


2.在res/anim/目录下添加一个animation资源文件,具体配置如下:

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"    android:shareInterpolator="true">    <alpha        android:fromAlpha="0"        android:toAlpha="1"        android:duration="1000"/>    <translate        android:fromXDelta="200"        android:toXDelta="0"        android:fromYDelta="200"        android:toYDelta="0"        android:duration="1000"        /></set>

3.在程序中实现按钮的点击事件之后利用AnimationUtils的loadAnimation方法来加载动画效果。

Animation a=AnimationUtils.loadAnimation(MainActivity.this, R.anim.animate);

4.使用startAnimation方法来为视图启动动画效果。

v.startAnimation(a);

animation对象同时还可以实现对animation事件的监听。

a.setAnimationListener(new Animation.AnimationListener() {    @Override    /**     *在动画开始时执行     */    public void onAnimationStart(Animation animation) {    }    @Override    /**     *在动画结束是执行     */    public void onAnimationEnd(Animation animation) {        Toast.makeText(MainActivity.this,"Animation End",Toast.LENGTH_SHORT).show();    }    @Override    /**     *在动画重绘时执行     */    public void onAnimationRepeat(Animation animation) {    }});

更多相关文章

  1. android 围绕中心旋转动画
  2. View的事件分发机制解析
  3. Android中触摸事件传递过程
  4. Android自定义动画类——实现3D旋转动画
  5. android view滑动助手类 OverScroller VelocityTracker
  6. Android(安卓)NDK进入发展
  7. 阿里ctf-2014 android 第一、二题
  8. 深入解析Android中View的工作原理
  9. Android之循环显示图像的Android(安卓)Gallery组件

随机推荐

  1. Android(安卓)Loader 机制浅谈
  2. android 获取MP4文件的图片大小
  3. Android中style和theme巧用:Android应用
  4. android 多表管理查询
  5. 为Android安装BusyBox —— 完整的bash s
  6. 2011的个人总结
  7. android6.0 系统时间不自动校准的问题
  8. Android(安卓)Camera CameraHal.cpp 分析
  9. Android之RecyclerView的局部刷新
  10. {Android} 测试Google Play In-App-Billi