Drawable Animation
来源:互联网 发布:办公室网络维护 编辑:程序博客网 时间:2024/05/18 20:07
Drawable animation是什么?
Drawable animation是一种动画类型。
Drawable animation的用途?
Drawable animation可以用来以你指定的顺序播放一组图片。可以循环播放,也可以只播放一次。
Drawable animation怎么使用?
Drawable animation可以在任何View上面使用,首先用AnimationDrawable对象设置View的Background,然后调用AnimationDrawable对象的start()
方法开始动画。
具体步骤如下:
1.用AnimationDrawable对象设置View的Background,有三种方式:
- [1].通过调用View的
setBackgroundResource(R.drawable.mydrawable)
方法设置View的Background [2].通过设置View的XML属性
and(和谐)roid:background="@drawable/mydrawable"
<?xml version="1.0" encoding="utf-8"?><!-- 方式[1]、[2]用到的 mydrawable.xml --><animation-list xmlns:android="http://schemas.android.com/apk/res/android" ><item android:drawable="@drawable/first" android:duration="300"/><item android:drawable="@drawable/second" android:duration="300"/><item android:drawable="@drawable/third" android:duration="300"/></animation-list>
- [3].通过代码创建AnimationDrawable对象,用其设置View的Background
//方式[3]用到的代码AnimationDrawable animationDrawable = new AnimationDrawable();animationDrawable.addFrame(getResources().getDrawable(R.drawable.first),300);animationDrawable.addFrame(getResources().getDrawable(R.drawable.second),300);animationDrawable.addFrame(getResources().getDrawable(R.drawable.third),300);animationDrawable.setOneShot(false);//设置循环一次就停止为false,即循环播放imageView.setBackgroundDrawable(animationDrawable);
2.用AnimationDrawable对象的start()
方法
((AnimationDrawable)imageView.getBackground()).start();
注意事项
SDK文档里面有这么一段话
It's important to note that the start() method called on the AnimationDrawable cannot be called during the onCreate() method of your Activity, because the AnimationDrawable is not yet fully attached to the window. If you want to play the animation immediately, without requiring interaction, then you might want to call it from the onWindowFocusChanged() method in your Activity, which will get called when Android brings your window into focus.
因此我们不能在Activity的onCreate()
方法里面调用View的start()
,而是在Activity的onWindowFocusChanged()
方法里面调用View的start()
运行效果图:
源码下载
0 0
- Drawable animation
- Drawable Animation
- Drawable Animation
- Drawable Animation
- Drawable Animation
- Android-animation-drawable Animation
- View Animation和Drawable Animation
- Android Drawable Animation 学习
- Android之Drawable Animation
- Drawable Animation 使用介绍
- android-Drawable Animation
- Android动画-Drawable Animation
- Drawable Animation(Android动画)
- Animation特效——Drawable Animation
- 【Android基础知识】Drawable Animation和View Animation
- Android Animation——drawable animation
- Android绘图动画---Drawable Animation
- Android动画之Drawable Animation
- 【Leetcode】之Minimum Path Sum
- QThread QT线程使用案例
- 前端开发学习指南
- Javascript(加快脚本加载速度的方法:压缩脚本文件。)
- PPT演讲者需要注意的事项
- Drawable Animation
- Android N 多窗口布局 省电模式 全新通知功能
- Android 检查更新版本(带有通知栏,进度条,Notification)
- 欢迎使用CSDN-markdown编辑器
- 羞羞的成人漫画笑话,18岁以下不要随意观看哦
- 那些年我们经历过的职场笑话
- oracle 序列
- ajax实现短信验证码功能
- React Native开发之FlexBox代码+图解