Animation(1、Tween Animation)

Android的补间动画,主要例子如下:

mImageView = (ImageView)findViewById(R.id.imageView1);



//透明度动画

AnimationSet animationSet = new AnimationSet(true);

//设置透明度

AlphaAnimation alphaAnimation = new AlphaAnimation(0,1);

//通用API

alphaAnimation.setDuration(2500); //设置持续时间

alphaAnimation.setStartOffset(1000); //设置延迟

alphaAnimation.setRepeatCount(2); //设置重复次数



//动画参数也可以设置在资源文件alpha.xml中

/*Animation animation = AnimationUtils.loadAnimation(

        Animation1Activity.this, R.anim.alpha);*/



//动画效果是可以叠加的!!

//animationSet.addAnimation(alphaAnimation);





//旋转动画

//参数1:开始旋转角度

//参数2:结束旋转角度

//参数3、4、5、6:设置旋转圆心,此例子中为中心,即自身长宽的一半处

RotateAnimation rotateAnimation = new RotateAnimation(0, 

        360,

        Animation.RELATIVE_TO_SELF,0.5f,

        Animation.RELATIVE_TO_SELF,0.5f);

 rotateAnimation.setDuration(5000);

 

 //差值器Interpolator,用以定义动画速率的变化

 animationSet.setInterpolator(new AccelerateInterpolator());

 animationSet.addAnimation(rotateAnimation);

 

 

 //伸缩动画

 //参数1~2:x轴的初始和结束长度,1f为自身长度;

 //参数3~4:y轴的初始和结束长度,1f为自身长度;

 //参数5~8:伸缩的轴心位置,类似旋转的圆心

 ScaleAnimation scaleAnimation = new ScaleAnimation(

         0, 1f,0,1f,

         Animation.RELATIVE_TO_SELF,1f,

         Animation.RELATIVE_TO_SELF,1f);

  scaleAnimation.setDuration(5000);

  //animationSet.addAnimation(scaleAnimation);



  //移动动画

  //参数1,2:设置x轴开始和结束的位置;

  //参数3,4:设置y轴开始和结束的位置

  TranslateAnimation translateAnimation =

  new TranslateAnimation(

      Animation.RELATIVE_TO_SELF,0f,

      Animation.RELATIVE_TO_SELF,0.5f,

      Animation.RELATIVE_TO_SELF,0f,

      Animation.RELATIVE_TO_SELF,0.5f);

   translateAnimation.setDuration(1000);

   //animationSet.addAnimation(translateAnimation);



   mImageView.startAnimation(animationSet);

 

你可能感兴趣的:(animation)