现在的位置: 首页 > 综合 > 正文

主题:android学习——android Animation

2013年12月22日 ⁄ 综合 ⁄ 共 2394字 ⁄ 字号 评论关闭
一种是tweened animation(渐变动画) 

XML中 

JavaCode 

alpha 

AlphaAnimation 

scale 

ScaleAnimation
一种是frame by frame(画面转换动画) 

XML中 

JavaCode 

translate 

TranslateAnimation 

rotate 

RotateAnimation

 

两种实现方法  

1 java 代码

 

  1. //
    TODO Auto-generated method stub
     
  2.             //第一个参数fromX为动画起始时
    X坐标上的伸缩尺寸    
     
  3.             //第二个参数toX为动画结束时
    X坐标上的伸缩尺寸     
     
  4.             //第三个参数fromY为动画起始时Y坐标上的伸缩尺寸     
  5.             //第四个参数toY为动画结束时Y坐标上的伸缩尺寸   
  6.             /*
  7.             
    * 说明: 以上四种属性值 0.0表示收缩到没有 1.0表示正常无伸缩 值小于1.0表示收缩 值大于1.0表示放大
  8.             
    */
     
  9.             //第五个参数pivotXType为动画在X轴相对于物件位置类型   
  10.             //第六个参数pivotXValue为动画相对于物件的X坐标的开始位置  
  11.             //第七个参数pivotXType为动画在Y轴相对于物件位置类型    
  12.             //第八个参数pivotYValue为动画相对于物件的Y坐标的开始位置  
  13.             ScaleAnimation scaleAnimation = new ScaleAnimation(1f, 0.5f,
    1f, 
    0.5f, 
  14.                     Animation.RELATIVE_TO_SELF, 0.5f, 
  15.                     Animation.RELATIVE_TO_SELF, 0.5f); 
  16.             scaleAnimation.setDuration(2000); 
  17.              
  18.             findViewById(R.id.img).setAnimation(scaleAnimation); 
  19.  
  20. //
    TODO Auto-generated method stub
     
  21.             //第一个参数fromDegrees为动画起始时的旋转角度     
  22.             //第二个参数toDegrees为动画旋转到的角度    
  23.             //第三个参数pivotXType为动画在X轴相对于物件位置类型   
  24.             //第四个参数pivotXValue为动画相对于物件的X坐标的开始位置  
  25.             //第五个参数pivotXType为动画在Y轴相对于物件位置类型    
  26.             //第六个参数pivotYValue为动画相对于物件的Y坐标的开始位置  
  27.             RotateAnimation rotateAnimation = new RotateAnimation(0180
  28.                     Animation.RELATIVE_TO_SELF, 0.5f, 
  29.                     Animation.RELATIVE_TO_SELF, 2.0f); 
  30.             rotateAnimation.setDuration(2000); 
  31.              
  32.             findViewById(R.id.img).setAnimation(rotateAnimation); 
  33.  
  34. //
    TODO Auto-generated method stub
     
  35.             //fromXDelta为动画起始时
    X坐标上的移动位置    
     
  36.             //toXDelta为动画结束时
    X坐标上的移动位置      
     
  37.             //fromYDelta为动画起始时Y坐标上的移动位置      
  38.             //toYDelta为动画结束时Y坐标上的移动位置  
  39.             //Animation.RELATIVE_TO_SELF
    相对本控件
     
  40.             TranslateAnimation translateAnimation
    new TranslateAnimation( 
  41.                     Animation.RELATIVE_TO_SELF, 1.0f, 
  42.                     Animation.RELATIVE_TO_SELF, 1.0f, 
  43.                     Animation.RELATIVE_TO_SELF, 1.0f, 
  44.                     Animation.RELATIVE_TO_SELF, 1.0f); 
  45.             //设置动画持续时间  
  46.             translateAnimation.setDuration(2000); 
  47.             findViewById(R.id.img).setAnimation(translateAnimation); 
  48.  
  49. //
    第一个参数fromAlpha为 动画开始时候透明度
     
  50.             //
    第二个参数toAlpha为 动画结束时候透明度
     
  51.             //
    0.0表示完全透明

抱歉!评论已关闭.