AnimationSet类:动画集合类

 AnimationSet类:动画集合类

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

【基本语法】public void addAnimation (Animation a)

其中,参数a为Animation动画对象,可以是前述任何一种补间动作。

【实例演示】下面通过代码来演示如何设置一个组合动画效果。

 
 
  1. public class firstActivity extends Activity {  
  2. /** Called when the activity is first created. */  
  3. @Override  
  4. public void onCreate(Bundle savedInstanceState) {               //重载onCreate方法  
  5.     super.onCreate(savedInstanceState);  
  6.     setContentView(R.layout.main);  
  7.  
  8.     final ImageView image=(ImageView)findViewById(R.id.imageView1); //ImageView对象  
  9.     Button btn1=(Button)findViewById(R.id.button1);             //按钮对象  
  10.     Button btn2=(Button)findViewById(R.id.button2);  
  11.     final Animation translateAnimation=new TranslateAnimation(0,300,0,300);                                                                 //设置位置变化动画  
  12.     final Animation scaleAnimation = new   
  13.      ScaleAnimation(0f,1f,0f,1f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);  
  14.                                                             //设置尺寸变化动画  
  15.     final Animation alphaAnimation=new AlphaAnimation(0.1f,1.0f);   //设置透明度变化动画  
  16.     btn1.setOnClickListener(new View.OnClickListener() {            //设置监听器  
  17.           
  18.         @Override  
  19.         public void onClick(View v) {  
  20.             // TODO Auto-generated method stub  
  21.             translateAnimation.setDuration(10000);      //设置位置变化动画的持续时间  
  22.             scaleAnimation.setDuration(10000);          //设置尺寸变化动画的持续时间  
  23.             alphaAnimation.setDuration(10000);          //设置透明度渐变动画的持续时间  
  24.             AnimationSet set=new AnimationSet(true);    //创建动画集对象  
  25.             set.addAnimation(translateAnimation);       //添加位置变化动画  
  26.             set.addAnimation(scaleAnimation);           //添加尺寸变化动画  
  27.             set.addAnimation(alphaAnimation);           //添加透明度渐变动画  
  28.             set.setFillAfter(true);                 //停留在最后的位置  
  29.             set.setFillEnabled(true);  
  30.             image.setAnimation(set);                    //设置动画  
  31.             set.startNow();                         //启动动画  
  32.         }  
  33.     });  
  34.     btn2.setOnClickListener(new View.OnClickListener() {    //设置监听器  
  35.           
  36.         @Override  
  37.         public void onClick(View v) {  
  38.             // TODO Auto-generated method stub  
  39.             set.cancel();                               //取消动画执行  
  40.         }  
  41.     });  
  42. }  
  43. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值