自动化零件服务商 - 供应SMC,FESTO,CKD全新正品气动元件
自动化零件服务商 - 供应SMC,FESTO,CKD全新正品气动元件
自动化零件服务商 - 供应SMC,FESTO,CKD全新正品气动元件

Android动画

  1. View Animation 视图动画(Tween Animation 补间动画),只能用来设置View的动画
  2. Drawable Animation 帧动画(Frame动画),一帧帧地显示资源文件中的Drawable
  3. Property Animation 属性动画,在android3.0以上的系统才有。这动画可以设置给任何的Object,包括那些还没有渲染到屏幕的view.

为什么要引入属性动画?

  1. 补间动画只能够作用在View上的
  2. 补间动画只能够实现移动、缩放、旋转和淡入淡出这四种动画操作,不能改变View的背景等
  3. 补间动画只是改变了View的显示效果而已,而不会真正去改变View的属性

View Animation 补间动画

视图动画也叫补间动画,指在一个视图容器中执行一些变换。包含有:位置、大小、旋转、透明 补间动画。

一般通过xml实现,不建议是用android代码实现,因为代码实现的可读性比较差。

补间动画的相关类
  • AlphaAnimation <alpha>放在res/anim/目录下 透明渐变动画效果
  • RotateAnimation <rotate>放在res/anim/目录下 旋转转移动画效果
  • ScaleAnimation <scale>放在res/anim/目录下 缩放动画效果
  • TranslateAnimation <translate>放在res/anim/目录下 移动动画效果
  • AnimationSet <set> 放在res/anim/目录下 持有动画的容器

补间动画之TranslateAnimation使用

实现TranslateAnimation有两种方式,一种是xml配置,一种是纯Java代码实现。

使用java代码实现
  1. // 使用方式一 默认类型是Animation.ABSOLUTE
  2. /**
  3. * @param fromXDelta x 坐标的起始点值
  4. * @param toXDelta x 坐标的终点值
  5. * @param fromYDelta y 坐标的起始点值
  6. * @param toYDelta y 坐标的终点值
  7. */
  8. translateAnimation = new TranslateAnimation(0,500,0,500);
  9.  
  10. /**
  11. * Constructor to use when building a TranslateAnimation from code
  12. *
  13. * @param fromXType 动画开始前的X坐标类型。取值范围为ABSOLUTE(绝对位置)、RELATIVE_TO_SELF(以自身宽或高为参考)、RELATIVE_TO_PARENT(以父控件宽或高为参考)。
  14. * @param fromXValue 动画开始前的X坐标值。当对应的Type为ABSOLUTE时,表示绝对位置;否则表示相对位置,1.0表示100%
  15. * @param toXType 结束后的x坐标类型(如fromXType一样)
  16. * @param toXValue 结束后的x坐标值(如fromXType一样)
  17. * @param fromYType 动画开始前的Y坐标类型(类型同fromXType)。
  18. * @param fromYValue 动画开始前的Y坐标值(值同fromXValue)。
  19. * @param toYType 动画结束后的Y坐标类型(类型同fromYType)。
  20. * @param toYValue 动画结束后的Y坐标值(值同fromYValue)。
  21. */
  22.  
  23. // 使用方式 二 自定义各类型,如下是都为Animation.ABSOLUTE时的用法(同一类似效果)
  24. // translateAnimation = new TranslateAnimation(Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 500, Animation.ABSOLUTE, 0, Animation.ABSOLUTE, 500);
  25.  
  26.  
  27. // 使用方式 三 自定义各类型,如下类型为Animation.RELATIVE_TO_PARENT或Animation.RELATIVE_TO_SELF时,后面带的参数值范围就变了。
  28. //translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 1.0f, Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 1.0f);
  29.  
  30. translateAnimation.setDuration(1000);
  31.  
  32. translateAnimation.setInterpolator(new LinearInterpolator());
  33.  
复制
使用xml实现

res/anim/anim_translate.xml

  1. <set xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:duration="1000">
  3.  
  4. <translate
  5. android:fromXDelta="0"
  6. android:fromYDelta="0"
  7. android:toXDelta="500"
  8. android:toYDelta="500" />
  9.  
  10. <!--
  11. 这种是绝对的类型。
  12. 跟如下代码一样的效果。
  13. translateAnimation = new TranslateAnimation(0,500,0,500);
  14. -->
  15.  
  16. </set>
复制
  1. animation = AnimationUtils.loadAnimation(this, R.anim.anim_translate);
复制

参考文章

  1. Android 动画Animation简单总结
  2. 补间动画详解四 平移动画TranslateAnimation
  3. Android 补间动画之平移动画TranslateAnimation
  4. Android三种动画详解
自动化零件服务商 - 供应SMC,FESTO,CKD全新正品气动元件

相关文章

自动化零件服务商 - 供应SMC,FESTO,CKD全新正品气动元件

暂无评论

none
暂无评论...