动画·Animation

2016-07-29  本文已影响22人  _人间客

简介:


android中的动画分为两种补间动画和帧动画

一、补间动画

通过移动控件的位置,改变透明度,控件的角度等实现的动画,可以设置监听。

(一)实现:

1.在res文件夹下创建anim文件夹

2.在anim文件夹下创建xml文件,选择resourceType为propertyAnimation,内容为set

animation.xml

系统会默认创建animator文件夹,新建的xml文件就在animator文件夹中,但这个文件夹不好用,不能自动提示(Android Sudio中已解决)。所以将xml文件移到自己创建的anim文件夹。


注意

3.在xml文件的set标签中配置相应的动画

(二)欢迎动画:

实现页面背景色透明度渐变

<set xmlns:android="http://schemas.android.com/apk/res/android"

android:fillAfter="true"> //动画结束时停在最后一帧渐变标签

<alpha

android:fromAlpha="1.0"

android:toAlpha="0"

android:duration="5000"   //执行时间

/>    </set>

(三)火箭发射:

<set></set>中间写入translate,

<translate

android:fromXDelta="0"//起始位置

android:toXDelta="0"

android:fromYDelta="0"

android:toYDelta="-70%p" //到达位置向上为负

android:duration="5000" />//经历时间(毫秒)

二、帧动画

通过快速地播放一组图片实现动画效果,不能监听,用定时器

(一)实现:

1.新建drawable文件夹,并在文件夹里新建xml文件,Root Element为animation-list

新建帧动画的xml

2.配置xml文件(Bomb_animation\change_animation\rocket_fire_animation)

按顺序引入图片,在duration里设置每张的显示时间(毫秒)

android:drawable = "@drawable/rocket_launch_2"//

android:duration = "200"

Code

三、音乐

新建raw文件夹,将音频文件引入(copy)

文件目录


上一篇下一篇

猜你喜欢

热点阅读