Android 杂谈---帧动画
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 杂谈---帧动画的更多相关文章
- Android 自定义帧动画
Android 自定义帧动画 Android L : Android Studio 帧动画 和gif图片类似,顺序播放准本好的图片文件:图片资源在xml文件中配置好 将图片按照预定的顺序一张张切换,即 ...
- Android使用帧动画内存溢出解决方法
Android使用帧动画内存溢出解决方法https://blog.csdn.net/daitu_liang/article/details/52336015https://blog.csdn.net/ ...
- Android 逐帧动画
原理: 逐帧动画是最简单的一种动画.原理就是把几张图片连续显示出来,以达到动画的效果.就相当于下面这种手绘翻页动画啦~ 实现: 1.需要建立一个animation-list来设置静态图片资源.持续时间 ...
- Android实现帧动画,以及出场时的动画
最近有个小需求,在数据上传的时候加一个上传的动画,然后就寻思着自己写一个帧动画 上传开始的时候调用动画,上传结束通知容器将其删除(这个方法应该不会太耗内存),然后吐槽下gif图片还是我自己一帧一帧从p ...
- android 通过帧动画方式播放Gif动画
注意:经过本人测试,这个方法很耗内存, 图片一多就崩了.慎用 <1>用工具(photoshop或者FireWorks)将GIF动画图片分解成多个GIF静态图片,然后保存在res\drawa ...
- Android 逐帧动画isRunning 一直返回true的问题
AnimationDrawabl主要通过xml实现逐帧动画,SDK实例如下: An AnimationDrawable defined in XML consists of a single < ...
- Android中帧动画的创建
帧动画,实质上就是快速播放多张连接效果的图片,现在一般可用于下拉刷新时候的headView 实现步骤: 1.首先应该准备一组连接效果的图片 2.在res>drawable目录下创建xml文件,将 ...
- Android 逐帧动画( Drawable 动画),这一篇就够了
前言 作为 Android 最常见的两种动画形式,逐帧动画( Drawable 动画),有着极其广泛的应用,它的原理与早起的电影以及 GIF 类似,就是把一张的图,按顺序快速切换,这样一来看上去就好像 ...
- Android之帧动画
MySurfaceView类: package com.fm; import android.content.Context; import android.graphics.Bitmap; impo ...
随机推荐
- js实现在光标的位置 添加内容
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- Python——Mysql
一.导入 import pymysql 二.连接 def connect_wxremit_db(): return pymysql.connect(host='10.123.5.28', port=3 ...
- MIUI9 解锁并刷入TWRP后,删除解锁密码
如果因为某种原因导致解锁密码失效(比如刷了其他ROM),还原备份回来之后,解锁密码失效了. 那么可以进入TWRP,然后通过 adb shell 进入\data\system\文件夹 用rm命令删除g ...
- 精心收集的 95 个超实用的 JavaScript 代码片段( ES6+ 编写)
https://www.html.cn/archives/8748#table-of-contents https://www.haorooms.com/post/js_regexp
- Linux 学习 (六) 关机与重启命令
Linux达人养成计划 I 学习笔记 shutdown [选项] 时间 -c:取消前一个关机命令 -h:关机 -r:重启 shutdown命令会在关机或重启时自动保存系统中正在运行的服务,最安全的关机 ...
- phpcms 标题设置
phpcms v9网站首页的标题可以控制,但是栏目页,内容页的标题非常的长,用户体验不好修改模板文件header html的<title> < title>改成 phpcms ...
- 版本控制工具之git
git存储区域详解 命令快速总结 初始化 git init 当前文件夹初始化 代码提交 git add file/. 自动检测工作区修改的内容提交到暂存区 git status 查看当前文件夹工作区的 ...
- django - 总结 - redis缓存
八.redis 补充- 操作 - 增删改查 对字典,重新设计结构,增删改查. hmset keys hget scan_iter hgetall import redis import j ...
- table 表格固定表头和第一列、内容可滚动
整理了下: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" c ...
- div的默认position值是静态的static
div的默认position值是静态的static,如果相对父元素使用Position:absolute的话,需要手动在父元素上添加Position.