Android动画之帧动画
来源:互联网 发布:ammnra折叠刀淘宝 编辑:程序博客网 时间:2024/05/31 13:14
通过定义一系列的drawable对象来创建一个帧动画,被用于一个视图的背景。
创建帧动画最简单的方式是定义一个XML的动画文件,放res/drawable/目录下并将其设置为一个视图对象的背景,然后调用start()方法运行动画。
一个帧动画的XML文件有一个和一系列内嵌的标签组成。每一项定义一帧动画,如下:
spin_animation.xml file in res/drawable/ folder:
<animation-list android id="@+id/selected" android oneshot="false"> <item android:drawable="@drawable/wheel0" duration="100"/> <item android:drawable="@drawable/wheel1" duration="100"/> <item android:drawable="@drawable/wheel2" duration="100"/> <item android:deawable="@drawable/wheel3" duration="100"/></animation-list>
注:
oneshot:为true时动画将只运行一次后就停止;为false动画将不停循环;
drawable:设置每帧动画显示的内容;
duration:设置每帧的显示时长,毫秒。
variablePadding:如果为true,允许drawable的padding根据当前的选择状态改变。
visible:提供drawable的初始可见状态,默认为false。
加载动画的代码:
ImageViewimg=(ImageView)findViewById(R.id.spinning_wheel_image);img.setBackgroundResource(R.drawable.spin_animation);AnimationDrawableframeAnimation=(AnimationDrawable)img.getBackground();frameAnimation.start();
更多:
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.(来自官方文档)
在Activity的onCreate()方法中不能调用帧动画的start()方法,因为帧动画尚未完全的加载到窗口上。你可以在Activity的onWindowFouseChanged()方法中调用动画。
但是:
如果在布局中给ImageView设置背景:
android:background="@drawable/spin_animation"
然后在Activity的onCreate()方法中调用:
ImageViewimg=(ImageView)findViewById(R.id.spinning_wheel_image);AnimationDrawableframeAnimation=(AnimationDrawable)img.getBackground();frameAnimation.start();
上述情况是可行的。
- Android动画之---帧动画
- Android 动画之帧动画
- Android动画之帧动画
- Android动画之帧动画
- Android动画之帧动画
- Android动画之帧动画
- Android——动画之帧动画
- Android开发之Frame动画(帧动画)
- Android动画之帧动画(一)
- android动画之 FrameAnimation(帧动画) AnimationDrawable
- android动画之逐帧动画
- Android动画学习之帧动画二
- Android动画之逐帧动画
- Android动画之帧动画实现方式
- Android动画之逐帧动画
- Android动画专题之逐帧动画
- android 动画详解之帧动画
- Android之动画-逐帧动画
- ssh连接服务器出现Agent admitted failure to sign using the key错误
- Android开发之drawable中的命名问题
- iOS Runtime详解(消息机制,类元对象,缓存机制,消息转发)
- 数据库基础知识
- 条件查找mongo, 并打印指定记录的单项Item
- Android动画之帧动画
- 【Jmeter学习01】Jmeter的介绍与下载安装
- SQL server 2008 R2 增加sa身份验证登陆
- ionic上拉加载-爬坑之路
- Fiddler教程--简介
- 关于Java Web框架之一的SpringMVC中Controller的返回值类型的理解
- classloader load apk
- textview文字过多,只显示前几个字,以...结束
- Unity延时功能的几种实现