android开发动画总结二(frame animation)
2015-07-23 13:49
429 查看
一、帧动画原理
所谓帧动画,就是搞一堆的图片,在一定的时间内连续的变换这些图片,从而导致产生动画的效果。所有我们平时在具体的项目中使用时,可按照如下的步骤去使用:1. 准备一些图片。
2. 在res/drawable目录下,创建一个类型为animation-list的xml文件。
3. 在代码中通过setImageResource方法将第二步创建的animation-list文件传递进去。
4. 通过控件的getDrawable方法获取AnimationDrawable对象,根据这个对象,调用start、stop方法就可以进行动画播放、停止了。
说实话,我在项目中很少使用帧动画的,因为属性动画实在太强大。不过,还是记录下来,加深记忆。
二、属性介绍
XML属性 | 说明 |
drawable | 当前帧引用的drawable资源 |
duration | 当前帧显示的时间(毫秒为单位) |
oneshot | 如果为true,表示动画只播放一次停止在最后一帧上,如果设置为false表示动画循环播放。 |
variablePadding | If true, allows the drawable’s padding to change based on the current state that is selected. |
visible | 规定drawable的初始可见性,默认为flase; |
三、示例程序
接下来通过一个示例程序,来加深印象,其实帧动画没什么技术含义,学会使用即可。1. 创建animation-list的文件,在res/drawable目录下创建一个animation.xml,内容如下:
<?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false" > <item android:drawable="@drawable/amp1" android:duration="150" > </item> <item android:drawable="@drawable/amp2" android:duration="150"> </item> <item android:drawable="@drawable/amp3" android:duration="150"> </item> <item android:drawable="@drawable/amp4" android:duration="150"> </item> <item android:drawable="@drawable/amp5" android:duration="150"> </item> <item android:drawable="@drawable/amp5" android:duration="150" > </item> </animation-list>
一共有六张图片,不断的播放这六张图片。
2. 在我的布局xml文件中,我是用imageview作为载体实现动画效果的,其中开始播放代码为:
iv.setImageResource(R.drawable.animation); dr = (AnimationDrawable) iv.getDrawable(); dr.start();停止播放代码:
dr.stop();
导致结束。
相关文章推荐
- Android获取View 的坐标和屏幕高度、状态栏高度、标题栏高度
- 【转】android自动化测试之MonkeyRunner使用实例(三)
- android屏幕适配
- Android 四大组件之Service
- 逆向Android软件的步骤
- Android图片异步加载框架Android-Universal-Image-Loader
- Android -- SEGV_MAPERR,SEGV_ACCERR
- Android百度 地图打开显示某坐标的地图
- Triumph! Android Studio 1.2 Sneaks In Full Testing Support(译文)
- Android 删除再创建导致open failed: EBUSY (Device or resource busy)
- AES加密解密在JAVA和ANDROID下互通
- Android中icon和logo的区别
- Android中icon和logo的区别
- android“设置”里的版本号
- Android调用系统日历插入日程
- 【原创】Android studio入门详细教程,首次启动配置,不翻墙搞定
- Android LruCache用于Bitmap
- android开发——camera类拍照指定图片大小
- Android studio 编译出现非法字符: \65279解决办法
- GitHub 优秀的 Android 开源项目