当前位置: 代码迷 >> Android >> Android卡通片效果translate、scale、alpha、rotate详解
  详细解决方案

Android卡通片效果translate、scale、alpha、rotate详解

热度:215   发布时间:2016-05-01 11:10:40.0
Android动画效果translate、scale、alpha、rotate详解

来自:http://blog.csdn.net/sun6255028/article/details/6735025

动画类型


Androidanimation由四种类型组成

XML

alpha渐变透明度动画效果
scale渐变尺寸伸缩动画效果
translate画面转换位置移动动画效果
rotate画面转移旋转动画效果



JavaCode

AlphaAnimation渐变透明度动画效果
ScaleAnimation渐变尺寸伸缩动画效果
TranslateAnimation画面转换位置移动动画效果
RotateAnimation画面转移旋转动画效果


Android动画模式

Animation主要有两种动画模式

一种是tweened animation(渐变动画)

XMLJavaCode
alphaAlphaAnimation
scaleScaleAnimation



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

?

XML中JavaCode
translateTranslateAnimation
rotateRotateAnimation

?

?

Android动画解析

alpha xml 淡出效果

?

?

[cpp]?view plaincopy
  1. <?xml?version="1.0"?encoding="utf-8"?>???
  2. <set?xmlns:android="http://schemas.android.com/apk/res/android">???
  3. <alpha???
  4. ????android:fromAlpha="1.0"????
  5. ????android:toAlpha="0.0"????
  6. ????android:duration="500"??/>???
  7. </set>???
  8. <!--????
  9. ????fromAlpha:开始时透明度???
  10. ????toAlpha:?结束时透明度???
  11. ????duration:动画持续时间?-->??

?

?

alpha xml 淡入效果

?

[cpp]?view plaincopy
  1. <?xml?version="1.0"?encoding="utf-8"?>???
  2. <set?xmlns:android="http://schemas.android.com/apk/res/android">???
  3. <alpha???
  4. ????android:fromAlpha="0.0"????
  5. ????android:toAlpha="1.0"????
  6. ????android:duration="500"??/>???
  7. </set>???
  8. <!--????
  9. ????fromAlpha:开始时透明度???
  10. ????toAlpha:?结束时透明度???
  11. ????duration:动画持续时间?-->??



?

rotate.xml 旋转效果:?

[html]?view plaincopy
  1. <?xml?version="1.0"?encoding="utf-8"?>???
  2. <set?xmlns:android="http://schemas.android.com/apk/res/android">??
  3. <rotate????????????????????????????????????????
  4. ????android:interpolator="@android:anim/accelerate_decelerate_interpolator"???
  5. ????android:fromDegrees="300"???
  6. ????android:toDegrees="-360"???
  7. ????android:pivotX="10%"???
  8. ????android:pivotY="100%"???
  9. ????android:duration="10000"?/>???
  10. </set>???
  11. <!--????
  12. ??fromDegrees???动画开始时的角度???
  13. ??toDegrees?????动画结束时物件的旋转角度,正代表顺时针?????
  14. ??pivotX????属性为动画相对于物件的X坐标的开始位置??
  15. ??pivotY????属性为动画相对于物件的Y坐标的开始位置????-->???



scale.xml 缩放效果:?

?

[cpp]?view plaincopy
  1. <?xml?version="1.0"?encoding="utf-8"?>???
  2. <set?xmlns:android="http://schemas.android.com/apk/res/android">???
  3. <scale?????
  4. ????android:interpolator=?"@android:anim/decelerate_interpolator"?????????
  5. ????android:fromXScale="0.0"?????
  6. ????android:toXScale="1.5"?????
  7. ????android:fromYScale="0.0"?????
  8. ????android:toYScale="1.5"?????
  9. ????android:pivotX="50%"?????
  10. ????android:pivotY="50%"?????
  11. ????android:startOffset="0"?????
  12. ????android:duration="10000"????
  13. ????android:repeatCount="1"?????
  14. ????android:repeatMode="reverse"??/>???
  15. </set>???
  16. ??
  17. <!--????
  18. fromXDelta,fromYDelta???????起始时X,Y座标,屏幕右下角的座标是X:320,Y:480???
  19. toXDelta,?toYDelta??????动画结束时X,Y的座标?-->?<!--????
  20. interpolator????????????????????指定动画插入器??
  21. 常见的有加速减速插入器?????????accelerate_decelerate_interpolator??
  22. 加速插入器???????????????accelerate_interpolator,??
  23. 减速插入器???????????????decelerate_interpolator。???
  24. fromXScale,fromYScale,?????????动画开始前X,Y的缩放,0.0为不显示,??1.0为正常大小??
  25. toXScale,toYScale,??????????动画最终缩放的倍数,?1.0为正常大小,大于1.0放大??
  26. pivotX,??pivotY?????????动画起始位置,相对于屏幕的百分比,两个都为50%表示动画从屏幕中间开始???
  27. startOffset,????????????????动画多次执行的间隔时间,如果只执行一次,执行前会暂停这段时间,??
  28. ????????????????????单位毫秒?duration,一次动画效果消耗的时间,单位毫秒,??
  29. ????????????????????值越小动画速度越快?repeatCount,动画重复的计数,动画将会执行该值+1次???
  30. ????????????????????repeatMode,动画重复的模式,reverse为反向,当第偶次执行时,动画方向会相反。??
  31. ????????????????????restart为重新执行,方向不变?-->??



?



translate.xml 移动效果:?

[html]?view plaincopy
  1. <?xml?version="1.0"?encoding="utf-8"?>???
  2. <set?xmlns:android="http://schemas.android.com/apk/res/android">??
  3. <translate???
  4. ????android:fromXDelta="320"???
  5. ????android:toXDelta="0"? ?

?

  相关解决方案