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对象

  • 相关阅读:
    python 下载文件保存到本地
    python 模拟udp客户端发送报文
    Block的底层代码实现
    常见的崩溃问题和类型
    NSTimer打破循环引用的几种方式
    springcloud alibaba Nacos解决OpenFeign调用失败问题
    LRU算法
    常见算法题解
    PHP无文件木马
    c++各种类型的字节数
  • 原文地址:https://www.cnblogs.com/taoshihan/p/5414640.html
Copyright © 2011-2022 走看看