星空网 > 软件开发 > 操作系统

[android] 帧动画和补间动画

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

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

添加<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_SELF,o.5f x以中心,Animation.RELATIVE_TO_SELF,0.5f y以中心

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

 

旋转

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

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

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

 

平移

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

相对于父窗体Animation.RELATIVE_TO_PARENT,0.0f

相对于父窗体Animation.RELATIVE_TO_PARENT,1.0f

相对于父窗体Animation.RELATIVE_TO_PARENT, 0.0f

相对于父窗体Animation.RELATIVE_TO_PARENT, 1.0f

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

 

组合动画

获取AnimationSet对象,new出来

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

 

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

多次添加就可以了

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

 




原标题:[android] 帧动画和补间动画

关键词:Android

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

tiktok国际版中文版:https://www.goluckyvip.com/tag/83942.html
国际版tiktok中文版:https://www.goluckyvip.com/tag/83943.html
tiktok成功:https://www.goluckyvip.com/tag/83944.html
tiktok出海计划:https://www.goluckyvip.com/tag/83945.html
tiktok创作收入:https://www.goluckyvip.com/tag/83946.html
tiktok访问:https://www.goluckyvip.com/tag/83947.html
37号文今后是否会更新?一文详解关键信息 :https://www.kjdsnews.com/a/1836441.html
探讨内地人开设香港账户的可行性 :https://www.kjdsnews.com/a/1836442.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流