动画效果

渐变尺寸(scale)动画效果:

[html]  view plain  copy
  1. <?xml version="1.0" encoding="utf-8"?>    
  2. <set xmlns:android="http://schemas.android.com/apk/res/android" >    
  3.     <scale    
  4.         android:duration="2000"    
  5.         android:fillAfter="false"    
  6.         android:fromXScale="0.0"    
  7.         android:fromYScale="0.0"    
  8.         android:interpolator="@android:anim/accelerate_decelerate_interpolator"    
  9.         android:pivotX="50%"    
  10.         android:pivotY="50%"    
  11.         android:toXScale="1.1"    
  12.         android:toYScale="1.1" />    
  13. </set>    
  14.   
  15. <!-- 尺寸伸缩动画效果 scale    
  16.        属性:interpolator 指定一个动画的插入器    
  17.        常见动画插入器:    
  18.             accelerate_decelerate_interpolator  加速-减速 动画插入器    
  19.             accelerate_interpolator        加速-动画插入器    
  20.             decelerate_interpolator        减速- 动画插入器    
  21.             anticipate_interpolator 先回退一小步然后加速前进    
  22.             anticipate_overshoot_interpolator   在上一个基础上超出终点一小步再回到终点    
  23.             bounce_interpolator 最后阶段弹球效果    
  24.             cycle_interpolator  周期运动    
  25.             linear_interpolator 匀速    
  26.             overshoot_interpolator  快速到达终点并超出一小步最后回到终点    
  27.       浮点型值:    
  28.               
  29.             fromXScale 属性为动画起始时 X坐标上的伸缩尺寸        
  30.             toXScale   属性为动画结束时 X坐标上的伸缩尺寸         
  31.              
  32.             fromYScale 属性为动画起始时Y坐标上的伸缩尺寸        
  33.             toYScale   属性为动画结束时Y坐标上的伸缩尺寸        
  34.              
  35.             说明:    
  36.                  以上四种属性值        
  37.          
  38.                     0.0表示收缩到没有     
  39.                     1.0表示正常无伸缩         
  40.                     值小于1.0表示收缩      
  41.                     值大于1.0表示放大    
  42.              
  43.             pivotX     属性为动画相对于物件的X坐标的开始位置    
  44.             pivotY     属性为动画相对于物件的Y坐标的开始位置    
  45.              
  46.             说明:    
  47.                     以上两个属性值 从0%-100%中取值    
  48.                     50%为物件的X或Y方向坐标上的中点位置    
  49.              
  50.         长整型值:    
  51.             duration  属性为动画持续时间    
  52.             说明:   时间以毫秒为单位    
  53.      
  54.         布尔型值:    
  55.             fillAfter 属性 当设置为true ,该动画转化在动画结束后被应用    
  56. -->    

混合动画:

[html]  view plain  copy
  1. <?xml version="1.0" encoding="utf-8"?>    
  2. <set xmlns:android="http://schemas.android.com/apk/res/android"    
  3.     android:repeatMode="reverse" >    
  4.     
  5.     <translate    
  6.         android:duration="1000"    
  7.         android:fromXDelta="0"    
  8.         android:fromYDelta="-15"    
  9.         android:repeatCount="infinite"    
  10.         android:toXDelta="0"    
  11.         android:toYDelta="20" />    
  12.     
  13.     <alpha    
  14.         android:duration="1000"    
  15.         android:fromAlpha="1.0"    
  16.         android:repeatCount="infinite"    
  17.         android:toAlpha="0.3" />    
  18.     
  19. </set>    
  20.   
  21. 混合动画是set集合,包含了平移动画(translate)和渐变动画(alpha),对这两动画简单说明:  
  22.   
  23. <alpha    
  24.       android:duration="1000"    
  25.       android:fromAlpha="1.0"    
  26.       android:repeatCount="infinite"    
  27.       android:toAlpha="0.3" />    
  28.   <!--    
  29.        透明度控制动画效果 alpha    
  30.       浮点型值:    
  31.           fromAlpha 属性为动画起始时透明度    
  32.           toAlpha   属性为动画结束时透明度    
  33.           说明:     
  34.               0.0表示完全透明    
  35.               1.0表示完全不透明    
  36.           以上值取0.0-1.0之间的float数据类型的数字    
  37.            
  38.       长整型值:    
  39.           duration  属性为动画持续时间    
  40.           说明:         
  41.               时间以毫秒为单位    
  42.       整型值:            
  43.           repeatCount:重复次数    
  44.           说明:    
  45.           infinite:循环执行,    
  46.           具体正整数表示循环次数    
  47.               
  48.            repeatMode:重复模式,    
  49.            说明:    
  50.               restart:重新从头开始执行    
  51.               reverse:反方向执行    
  52.                
  53.   -->    
  54.   
  55. <translate    
  56.      android:duration="1000"    
  57.      android:fromXDelta="0"    
  58.      android:fromYDelta="-15"    
  59.      android:repeatCount="infinite"    
  60.      android:toXDelta="0"    
  61.      android:toYDelta="20" />    
  62.  <!-- translate 平移动画效果    
  63.      整型值:    
  64.          fromXDelta 属性为动画起始时 X坐标上的位置        
  65.          toXDelta   属性为动画结束时 X坐标上的位置    
  66.          fromYDelta 属性为动画起始时 Y坐标上的位置    
  67.          toYDelta   属性为动画结束时 Y坐标上的位置    
  68.          注意:    
  69.                   没有指定fromXType toXType fromYType toYType 时候,    
  70.                   默认是以自己为相对参照物  ,默认参考物最重要             
  71.      长整型值:    
  72.          duration  属性为动画持续时间    
  73.          说明:   时间以毫秒为单位  --!>  


旋转(rotate)动画和 渐变尺寸动画的组合:

[html]  view plain  copy
  1. <?xml version="1.0" encoding="utf-8"?>    
  2. <set xmlns:android="http://schemas.android.com/apk/res/android" >    
  3.     
  4.     <scale    
  5.         android:duration="800"    
  6.         android:fillAfter="false"    
  7.         android:fromXScale="0.0"    
  8.         android:fromYScale="0.0"    
  9.         android:interpolator="@android:anim/accelerate_decelerate_interpolator"    
  10.         android:pivotX="50%"    
  11.         android:pivotY="50%"    
  12.         android:toXScale="1.2"    
  13.         android:toYScale="1.2" />    
  14.     
  15.     <rotate    
  16.         android:duration="3000"    
  17.         android:fromDegrees="0"    
  18.         android:pivotX="50%"    
  19.         android:pivotY="50%"    
  20.         android:repeatCount="-1"    
  21.         android:toDegrees="359.0" />    
  22.     
  23. </set>    
  24.   
  25. 前面介绍了渐变尺寸动画,下面只介绍旋转动画:  
  26.   
  27. <rotate    
  28.         android:duration="3000"    
  29.         android:fromDegrees="0"    
  30.         android:pivotX="50%"    
  31.         android:pivotY="50%"    
  32.         android:repeatCount="-1"    
  33.         android:toDegrees="359.0" />    
  34.     <!-- rotate 旋转动画效果    
  35.        属性:interpolator 指定一个动画的插入器    
  36.                
  37.        浮点数型值:    
  38.             fromDegrees 属性为动画起始时物件的角度        
  39.             toDegrees   属性为动画结束时物件旋转的角度 可以大于360度       
  40.      
  41.              
  42.             说明:    
  43.                      当角度为负数——表示逆时针旋转    
  44.                      当角度为正数——表示顺时针旋转                  
  45.                      (负数from——to正数:顺时针旋转)       
  46.                      (负数from——to负数:逆时针旋转)     
  47.                      (正数from——to正数:顺时针旋转)     
  48.                      (正数from——to负数:逆时针旋转)           
  49.      
  50.             pivotX     属性为动画相对于物件的X坐标的开始位置    
  51.             pivotY     属性为动画相对于物件的Y坐标的开始位置    
  52.                      
  53.             说明:        以上两个属性值 从0%-100%中取值    
  54.                          50%为物件的X或Y方向坐标上的中点位置    
  55.      
  56.         长整型值:    
  57.             duration  属性为动画持续时间    
  58.             说明:       时间以毫秒为单位    
  59. -->    

使用animation-list实现的逐帧动画:

[html]  view plain  copy
  1. <?xml version="1.0" encoding="utf-8"?>    
  2. <animation-list xmlns:android="http://schemas.android.com/apk/res/android"    
  3.     android:oneshot="false" >    
  4. <!--       
  5.     根标签为animation-list,其中oneshot代表着是否只展示一遍,设置为false会不停的循环播放动画      
  6.     根标签下,通过item标签对动画中的每一个图片进行声明      
  7.     android:duration 表示展示所用的该图片的时间长度      
  8.  -->      
  9.     <item    
  10.         android:drawable="@drawable/tutorial1_icon1"    
  11.         android:duration="200"/>    
  12.     <item    
  13.         android:drawable="@drawable/tutorial1_icon2"    
  14.         android:duration="200"/>    
  15.     
  16. </animation-list>  


Java代码的实现动画:


AlphaAnimation   渐变透明度动画效果:

[java]  view plain  copy
  1. AnimationSet animationSet = new AnimationSet(true);//创建一个AnimationSet对象      
  2. AlphaAnimation alphaAnimation = new AlphaAnimation(10);//创建一个AlphaAnimation对象               
  3. alphaAnimation.setDuration(1000);//设置动画执行的时间(单位:毫秒)           
  4. animationSet.addAnimation(alphaAnimation);//将AlphaAnimation对象添加到AnimationSet当中            
  5. view.startAnimation(animationSet);//使用view的startAnimation方法开始执行动画   <span style="color: rgb(0, 130, 0); line-height: 18px; font-family: Consolas, 'Courier New', Courier, mono, serif; background-color: inherit;">   </span>  
RotateAnimation  画面转移旋转动画效果:

[java]  view plain  copy
  1. AnimationSet animationSet = new AnimationSet(true);    
  2. /**   
  3. * 前两个参数定义旋转的起始和结束的度数,后两个参数定义圆心的位置   
  4. */    
  5. RotateAnimation rotateAnimation = new RotateAnimation(0360,        
  6.                     Animation.RELATIVE_TO_PARENT, 1f,        
  7.                     Animation.RELATIVE_TO_PARENT, 0f);        
  8.             rotateAnimation.setDuration(5000);        
  9.             animationSet.addAnimation(rotateAnimation);        
  10.             imageView.startAnimation(animationSet);   
TranslateAnimation  画面转换位置移动动画效果:

[java]  view plain  copy
  1. AnimationSet animationSet = new AnimationSet(true);        
  2. /**   
  3.              * x和y轴的起始和结束位置   
  4. */    
  5. TranslateAnimation translateAnimation = new TranslateAnimation        
  6.             (        
  7.                     Animation.RELATIVE_TO_SELF, 0f,         
  8.                     Animation.RELATIVE_TO_SELF,0.5f,         
  9.                     Animation.RELATIVE_TO_SELF, 0f,        
  10.                     Animation.RELATIVE_TO_SELF, 1.0f        
  11.             );        
  12.             translateAnimation.setDuration(1000);        
  13.             animationSet.addAnimation(translateAnimation);        
  14. view.startAnimation(animationSet);   
ScaleAnimation  渐变尺寸伸缩动画效果:

[java]  view plain  copy
  1. AnimationSet animationSet = new AnimationSet(true);        
  2. /**   
  3.              * 围绕一个点伸缩   
  4. */    
  5. ScaleAnimation scaleAnimation = new ScaleAnimation(10.1f, 1,        
  6.                     0.1f, Animation.RELATIVE_TO_SELF, 0.5f,        
  7.                     Animation.RELATIVE_TO_SELF, 0.5f);        
  8.             animationSet.addAnimation(scaleAnimation);        
  9.             animationSet.setStartOffset(1000);        
  10.             animationSet.setFillAfter(true);        
  11.             animationSet.setFillBefore(false);        
  12.             animationSet.setDuration(2000);        
  13. view.startAnimation(animationSet);  



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值