zoukankan      html  css  js  c++  java
  • [android] 帧动画和补间动画

     逐帧显示一张图片,连起来成为动画

    res/drawable/目录下,创建一个xxx.xml的文件

    添加<animation-list>节点,设置是否循环android:oneshot:”false”

    添加条目<item>节点,设置资源android:drawable=”@drawable/xxx”

    设置执行时间,android:duration=”100”

    逐帧添加对应的图片

    获取ImageView对象,通过findViewById()

    调用ImageView对象的setBackgroundResource()设置背景资源,参数:资源文件

    调用ImageView对象的getBackground()方法获取到AnimationDrawable对象

    getBackground()方法是异步的在一个单独的线程里面执行的,因此,有时候,下面的代码是播放不了的,建议放在按钮点击事件里,或者屏幕触摸事件里

    调用AnimationDrawable对象start()方法,开始播放

     tween动画

    透明度

    获取AlphaAnimation对象,new AlphaAnimation(),参数:从0.0f透明度,到1.0f透明度

    AlphaAnimation对象的setDuration()方法,设置执行时间

    调用View对象的startAnimation()方法,参数:AlphaAnimation对象

    缩放

    获取ScaleAnimation对象,new ScaleAnimation(),参数:

    原始宽,变化后宽,原始高,变化后高,Animation.RELATIVE_TO_SELFo.5f x以中心,Animation.RELATIVE_TO_SELF0.5f y以中心

    调用View对象的startAnimation()方法,参数:ScaleAnimation对象

    旋转

    获取RotateAnimation对象,new RotateAnimation(),参数:

    0开始选择,旋转360度,旋转中心Animation.RELATIVE_TO_SELFo.5f x以中心,旋转中心Animation.RELATIVE_TO_SELFo.5f x以中心

    调用View对象的startAnimation()方法,参数:RotateAnimation对象

    平移

    获取TranslateAnimation对象,new TranslateAnimation(),参数:

    相对于父窗体Animation.RELATIVE_TO_PARENT0.0f

    相对于父窗体Animation.RELATIVE_TO_PARENT1.0f

    相对于父窗体Animation.RELATIVE_TO_PARENT0.0f

    相对于父窗体Animation.RELATIVE_TO_PARENT1.0f

    调用View对象的startAnimation()方法,参数:TranslateAnimation对象

    组合动画

    获取AnimationSet对象,new出来

    获取到上面的多个动画对象

    调用AnimationSet对象的addAnimation()方法,把动画添加进来,参数:动画

    多次添加就可以了

    调用View对象的startAnimation()方法,参数:AnimationSet对象

  • 相关阅读:
    临床是什么意思
    .NET编程 TripleDES加解密范例
    七个C#编程的小技巧
    什么是医技科室
    NT Service与桌面交互
    如何在全局程序集缓存 (GAC) 中安装 DLL 文件
    C# 获取机器码
    .NET编程 字节数组、数值和十六进制字符串的转换
    C#.Net的全局键盘钩子(Hook)技术
    VS2008安装"deffactory.dat"文件错误解决方法
  • 原文地址:https://www.cnblogs.com/taoshihan/p/5414640.html
Copyright © 2011-2022 走看看