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

  • 相关阅读:
    HTTP 协议中的并发限制及队首阻塞问题
    聊聊JMM
    聊聊CacheLine
    git解决本地建立git仓库 连接远程git仓库出现拒绝合并问题
    django 本地项目部署uwsgi 以及云服务器部署 uwsgi+Nginx+Docker+MySQL主从
    我的第一篇播客
    大爷的超市管理系统——冲刺第一天
    能混绝不C——凡事预则立
    2020软件工程团队作业——05
    2020软件工程作业——04
  • 原文地址:https://www.cnblogs.com/taoshihan/p/5414640.html
Copyright © 2011-2022 走看看