Android中的动画有

大体思路

1.需要定义存放每一帧的xml文件,放在drawable文件夹下

设置图片路径和duration,以及shot属性,false--->只播放一次,true----->播放多次

 <?xml version="1.0" encoding="utf-8"?>
<animation-list android:oneshot="false" xmlns:android="http://schemas.android.com/apk/res/android">
<item android:duration="50" android:drawable="@drawable/progressbar34" />
<item android:duration="50" android:drawable="@drawable/progressbar33" />
<item android:duration="50" android:drawable="@drawable/progressbar32" />
<item android:duration="50" android:drawable="@drawable/progressbar31" />
<item android:duration="50" android:drawable="@drawable/progressbar30" />
<item android:duration="50" android:drawable="@drawable/progressbar29" />
<item android:duration="50" android:drawable="@drawable/progressbar28" />
<item android:duration="50" android:drawable="@drawable/progressbar27" />
<item android:duration="50" android:drawable="@drawable/progressbar26" />
<item android:duration="50" android:drawable="@drawable/progressbar25" />
<item android:duration="50" android:drawable="@drawable/progressbar24" />
<item android:duration="50" android:drawable="@drawable/progressbar23" />
<item android:duration="50" android:drawable="@drawable/progressbar22" />
<item android:duration="50" android:drawable="@drawable/progressbar21" />
<item android:duration="50" android:drawable="@drawable/progressbar20" />
<item android:duration="50" android:drawable="@drawable/progressbar19" />
<item android:duration="50" android:drawable="@drawable/progressbar18" />
<item android:duration="50" android:drawable="@drawable/progressbar17" />
<item android:duration="50" android:drawable="@drawable/progressbar16" />
<item android:duration="50" android:drawable="@drawable/progressbar15" />
<item android:duration="50" android:drawable="@drawable/progressbar14" />
<item android:duration="50" android:drawable="@drawable/progressbar13" />
<item android:duration="50" android:drawable="@drawable/progressbar12" />
<item android:duration="50" android:drawable="@drawable/progressbar11" />
<item android:duration="50" android:drawable="@drawable/progressbar10" />
<item android:duration="50" android:drawable="@drawable/progressbar9" />
<item android:duration="50" android:drawable="@drawable/progressbar8" />
<item android:duration="50" android:drawable="@drawable/progressbar7" />
<item android:duration="50" android:drawable="@drawable/progressbar6" />
<item android:duration="50" android:drawable="@drawable/progressbar5" />
<item android:duration="50" android:drawable="@drawable/progressbar4" />
<item android:duration="50" android:drawable="@drawable/progressbar3" />
<item android:duration="50" android:drawable="@drawable/progressbar2" />
<item android:duration="50" android:drawable="@drawable/progressbar1" />
</animation-list>

progress.xml

2.指定存放该动画的容器,使用imageView来充当

 <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.jing.www.loginlightdemo.MainActivity">
<ImageView
android:id="@+id/animation_iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:src="@drawable/progress" /> </android.support.constraint.ConstraintLayout>

activity_main.xml

3.使用代码来播放帧动画

注意:不能再onCreate()方法中进行动画的播放,动画依附于window,在onCreate()时期,window还没有初始化完成

会使动画没有运行而是停留在第一帧,那是因为AnimationDrawable播放动画是依附在window上面,而在Activity onCreate方法中调用时Window还未初始化完毕,所有才会停留在第一帧,要想实现播放必须在onWindowFocusChanged中添加如下代码:

 public class MainActivity extends AppCompatActivity {

     private ImageView imageView;

     @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView) findViewById(R.id.animation_iv); } @Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
imageView.setImageResource(R.drawable.progress);
AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getDrawable();
animationDrawable.start(); }
}

MainActivity.java

Android 杂谈---帧动画的更多相关文章

  1. Android 自定义帧动画

    Android 自定义帧动画 Android L : Android Studio 帧动画 和gif图片类似,顺序播放准本好的图片文件:图片资源在xml文件中配置好 将图片按照预定的顺序一张张切换,即 ...

  2. Android使用帧动画内存溢出解决方法

    Android使用帧动画内存溢出解决方法https://blog.csdn.net/daitu_liang/article/details/52336015https://blog.csdn.net/ ...

  3. Android 逐帧动画

    原理: 逐帧动画是最简单的一种动画.原理就是把几张图片连续显示出来,以达到动画的效果.就相当于下面这种手绘翻页动画啦~ 实现: 1.需要建立一个animation-list来设置静态图片资源.持续时间 ...

  4. Android实现帧动画,以及出场时的动画

    最近有个小需求,在数据上传的时候加一个上传的动画,然后就寻思着自己写一个帧动画 上传开始的时候调用动画,上传结束通知容器将其删除(这个方法应该不会太耗内存),然后吐槽下gif图片还是我自己一帧一帧从p ...

  5. android 通过帧动画方式播放Gif动画

    注意:经过本人测试,这个方法很耗内存, 图片一多就崩了.慎用 <1>用工具(photoshop或者FireWorks)将GIF动画图片分解成多个GIF静态图片,然后保存在res\drawa ...

  6. Android 逐帧动画isRunning 一直返回true的问题

    AnimationDrawabl主要通过xml实现逐帧动画,SDK实例如下: An AnimationDrawable defined in XML consists of a single < ...

  7. Android中帧动画的创建

    帧动画,实质上就是快速播放多张连接效果的图片,现在一般可用于下拉刷新时候的headView 实现步骤: 1.首先应该准备一组连接效果的图片 2.在res>drawable目录下创建xml文件,将 ...

  8. Android 逐帧动画( Drawable 动画),这一篇就够了

    前言 作为 Android 最常见的两种动画形式,逐帧动画( Drawable 动画),有着极其广泛的应用,它的原理与早起的电影以及 GIF 类似,就是把一张的图,按顺序快速切换,这样一来看上去就好像 ...

  9. Android之帧动画

    MySurfaceView类: package com.fm; import android.content.Context; import android.graphics.Bitmap; impo ...

随机推荐

  1. IO多路复用和local概念

    一.local 在多个线程之间使用threading.local对象,可以实现多个线程之间的数据隔离 import time import random from threading import T ...

  2. Civil 3D .NET二次开发第11章代码升级至2018版注意事项

    原来涉及2017的,均需要改为2018 原来的21改为22 代码中AeccXUiLand.AeccApplication.11.0"改为AeccXUiLand.AeccApplication ...

  3. Django+Vue打造购物网站(十一)

    第三方登录 微博创建应用,修改回调地址 http://open.weibo.com/authentication 安装第三方登录插件 https://github.com/python-social- ...

  4. 【XSY3156】简单计数II 容斥 DP

    题目大意 定义一个序列的权值为:把所有相邻的相同的数合并为一个集合后,所有集合的大小的乘积. 特别的,第一个数和最后一个数是相邻的. 现在你有 \(n\) 种数,第 \(i\) 种有 \(c_i\) ...

  5. Codeforces #381(div2)

    A.题目:http://codeforces.com/contest/740/problem/A 题意:现有n本书,买一本书需要花a元,两本书b元,三本书c元,问买够书是4的倍数所需要的最小花费 思路 ...

  6. zabbix存储history_text

    有一个监控项存储一个目录的所有文件(递归)信息,字符数量比较大,history_str表的value的字段字符数限制为255长度,所以就想存储到history_text表中,在最新数据中一直显示不出新 ...

  7. JMeter 不同线程组间变量传递

    JMeter元件都是有作用域的,而变量大多使用正则表达式提取器,要想在不通过线程组件使用变量参数,则需要设置全部变量 JMeter函数助手就提供了一个函数用于设置全局变量属性,实现的功能类似于在用户自 ...

  8. python之模块之shutil模块

    shutil -- --High-level file operations  高级的文件操作模块. os模块提供了对目录或者文件的新建/删除/查看文件属性,还提供了对文件以及目录的路径操作.比如说: ...

  9. usb输入子系统写程序(三)

    目录 usb输入子系统写程序 小结 内核修改 怎么写代码 类型匹配 probe disconnect 程序设计 1th匹配probe 2th 获取usb数据 3th 输入子系统上报按键 title: ...

  10. 机器学习 - 正则化L1 L2

    L1 L2 Regularization 表示方式: $L_2\text{ regularization term} = ||\boldsymbol w||_2^2 = {w_1^2 + w_2^2 ...