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 ...
随机推荐
- 数据标记系列——图像分割 & PolygonRNN++(一)
当前大多数图像语义分割算法都是基于深度学习的方式,但是深度学习的效果很大程度上是依赖于大量训练数据的.目前的图像分割方法无非两种,一种是通过标注人员手动标注,如Cityscapes(提供无人驾驶环境下 ...
- 关于CentOS7.2 控制面板不显示输入法,或者无法调出输入的问题。(已解决)
问题描述: CentOS7.2 桌面系统控制面板突然就不显示输入法的图标,快捷键也调不出输入法. 解决方法: test@base0200: ~ $ ibus-setup 调出ibus首选项--> ...
- 使用chrome开发者工具中的network面板测量网站网络性能
前面的话 Chrome 开发者工具是一套内置于Google Chrome中的Web开发和调试工具,可用来对网站进行迭代.调试和分析.使用 Network 面板测量网站网络性能.本文将详细介绍chrom ...
- python常用的基本操作
打开cmd,pip list 可以查看python安装的所以第三方包
- C. New Year and Rating 差分方程 思维
题意: 一个CF玩家打CF 给出其比赛列表和上分(掉分)情况 ,但是没给初始分 问最后最高分是多少 (情况不存在,或者可能无穷大) 思路: 设初始分为x 那么之前的回合的分数前缀和为sum 如 ...
- n98-magerun2.phar
installl: 1,cd /usr/local/bin && curl -O https://files.magerun.net/n98-magerun2.phar 2,chmod ...
- radio,check美化
单选框与复选框原生控件美化有多种解决方案,现在采用经典的input+label的方式自己实现一种 思路: input 和label 通过id和for属性关联,点击label时,input选中状态改变 ...
- BZOJ3864: Hero meet devil(dp套dp)
Time Limit: 8 Sec Memory Limit: 128 MBSubmit: 397 Solved: 206[Submit][Status][Discuss] Description ...
- MacBook 整个配置过程,供新入手MacBook的同学
这里记录了MacBook 的整个配置过程,可供新入手MacBook和觉得MacBook比较难用的同学参考. 1. 外围拓展 笔记本电脑的特点是携带方便,缺点是屏幕太小,因此你首先需要再申请领用一个外接 ...
- Go语言系列(七)- 读写操作
终端读写 1. 终端读写 操作终端相关文件句柄常量 os.Stdin:标准输入 os.Stdout:标准输出 os.Stderr:标准错误输出 2. 终端读写示例 package main impor ...