Android Animation学习(六) View Animation介绍

View Animation

  View animation系统可以用来执行View上的Tween animationFrame animation

  Tween animation可以在View对象上执行一系列的简单变换,比如位置、尺寸、旋转、透明度等。

  animation package包中包含了tween animation所有的类。

  一系列的动画命令定义了一个完整的tween animation,可以用代码定义也可以用XML资源文件定义。

XML资源文件

  XML资源文件的使用可以见:Animation Resources

  XML文件放在项目的res/anim/目录下。文件必须有一个唯一的根节点。

  这个根节点可以是:<alpha>, <scale>, <translate>, <rotate>, interpolator element, 或者是<set>。

  默认情况下,所有的动画都是并行进行的,要想使得它们顺寻发生,你必须指定startOffset属性。

  有一些值,可以指定是相对于View本身还是相对于父类容器的。

  比如pivotX,要表示相对于自身的50%,要用50%;要表示相对于父类容器的50%,则直接写50

使用例子

  XML文件存储为:res/anim/hyperspace_jump.xml:

<set xmlns:android="http://schemas.android.com/apk/res/android"    android:shareInterpolator="false">    <scale        android:interpolator="@android:anim/accelerate_decelerate_interpolator"        android:fromXScale="1.0"        android:toXScale="1.4"        android:fromYScale="1.0"        android:toYScale="0.6"        android:pivotX="50%"        android:pivotY="50%"        android:fillAfter="false"        android:duration="700" />    <set        android:interpolator="@android:anim/accelerate_interpolator"        android:startOffset="700">        <scale            android:fromXScale="1.4"            android:toXScale="0.0"            android:fromYScale="0.6"            android:toYScale="0.0"            android:pivotX="50%"            android:pivotY="50%"            android:duration="400" />        <rotate            android:fromDegrees="0"            android:toDegrees="-45"            android:toYScale="0.0"            android:pivotX="50%"            android:pivotY="50%"            android:duration="400" />    </set></set>

  在代码中把这个动画应用于一个ImageView:

ImageView image = (ImageView) findViewById(R.id.image);Animation hyperspaceJump = AnimationUtils.loadAnimation(this, R.anim.hyperspace_jump);image.startAnimation(hyperspaceJump);
  

  除了调用startAnimation() ,另一种处理方式是通过Animation.setStartTime()方法定义一个开始时间,然后通过View.setAnimation()方法把这个动画赋给控件即可。

View Animation和Property Animation

  View Animation是API Level 1就引入的。

  View Animation在包android.view.animation中。

  动画类叫Animation

  Property Animation是API Level 11引入的,即Android 3.0才开始有Property Animation相关的API。

  Property Animation API在包android.animation中。

  动画相关类叫Animator

参考资料

  API Guides:View Animation

  http://developer.android.com/guide/topics/graphics/view-animation.html

  Tween animation的包:

  http://developer.android.com/reference/android/view/animation/package-summary.html

  Animation类:

  http://developer.android.com/reference/android/view/animation/Animation.html

  Animation Resources

  http://developer.android.com/guide/topics/resources/animation-resource.html

更多相关文章

  1. Android动画效果translate、scale、alpha、rotate的 xml文件写法
  2. build/envsetup.sh简记Android
  3. Android(安卓)adapter适配器的使用
  4. DTMF信号处理
  5. android多国语言与国际化
  6. Android(安卓)开源动画框架 NineOldAndroids
  7. android自定义Adapter
  8. Android顶部弹出提示语的三种实现方式:WindowManager、PopupWindo
  9. Android(安卓)自定义可编辑可任意全屏拖动的EditText

随机推荐

  1. Android 9Patch图片
  2. Android系列教程(三)
  3. eclipse ADT在线安装 https://dl-ssl.goo
  4. Android之自定义checkbox样式
  5. Android(安卓)应用程序组件学习
  6. Android驱动程序开发和调试环境配置
  7. Android API demos 阅读笔记 1
  8. Android关于图片压缩
  9. canvas 画一个圆上有 旋转角度 的直线
  10. Mac与Android文件传输工具 Android File