1.5.35 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:

 

<span style="font-size:14px;"><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></span>

 

  在代码中把这个动画应用于一个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

 

以上转载:http://www.cnblogs.com/mengdd/p/3309731.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值