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. java进阶学习的一些思路

    搞 Java 的年薪 40W 是什么水平? - 乔戈里的回答 - 知乎 https://www.zhihu.com/question/31437847/answer/566852748 在知乎上看了他 ...

  2. [Linux] Vim 撤销 回退 操作

    在vi中按u可以撤销一次操作 u   撤销上一步的操作      Ctrl+r 恢复上一步被撤销的操作 注意:        如果你输入“u”两次,你的文本恢复原样,那应该是你的Vim被配置在Vi兼容 ...

  3. 使用ServletContext对象读取资源文件

    备注:本文以properties文件为例 一.通过ServletContext读取文件 1.通过ServletContext读取放置在src下的properties文件 package com; im ...

  4. FWT快速沃尔什变换学习笔记

    FWT快速沃尔什变换学习笔记 1.FWT用来干啥啊 回忆一下多项式的卷积\(C_k=\sum_{i+j=k}A_i*B_j\) 我们可以用\(FFT\)来做. 甚至在一些特殊情况下,我们\(C_k=\ ...

  5. Ceph分布式存储(luminous)部署文档-ubuntu18-04

    Ceph分布式存储(luminous)部署文档 环境 ubuntu18.04 ceph version 12.2.7 luminous (stable) 三节点 配置如下 node1:1U,1G me ...

  6. python之路day01--变量

    一.变量 变量就是将一些运算的中间结果暂存到内存中,以便后续代码块调用. 规范: 1.必须由数字.字母.下划线任意组合,且不能数字开头. 2.不能是python中的关键字.如:‘print’ 'and ...

  7. git && gitlab 使用

    安装略过 使用 基于公钥的认证登录,方便对用户进行权限控制 useradd -s /usr/bin/git-shell testgit #创建一个用户 或者直接useradd testgit 然后去/ ...

  8. NET Core 控制台程序读 appsettings.json 、注依赖、配日志、设 IOptions

    .NET Core 控制台程序没有 ASP.NET Core 的 IWebHostBuilder 与 Startup.cs ,那要读 appsettings.json.注依赖.配日志.设 IOptio ...

  9. JAVA实现C/S结构小程序

    程序功能: 客户端向服务器发送一个本地磁盘中的文件, 服务器程序接受后保存在其他位置. 客户端实现步骤: 创建一个客户端对象Socket,构造方法中绑定服务器的IP地址 和 端口号 使用Socket对 ...

  10. 使用C语言中qsort()函数对浮点型数组无法成功排序的问题

    一 写在开头 1.1 本节内容 本节主要内容是有关C语言中qsort()函数的探讨. 二 问题和相应解决方法 qsort()是C标准库中的一个通用的排序函数.它既能对整型数据进行排序也能对浮点型数据进 ...