Android 用Animation-list实现逐帧动画 (转载)
转自:http://blog.csdn.net/aminfo/article/details/7847761
第一步:先上图片素材,以下素材放到res/drawable目录下:
http://blog.csdn.net/aminfo/article/details/7847761
图片素材:

文件名称:icon1.png icon2.png icon3.png icon4.png icon5.png icon6.png
第二步:上动画Animation-list帧布局文件,有2个,一个是按顺序显示动画,一个是倒序显示动画,文件存放在res/drawable目录下
顺序显示动画文件:animation1.xml
<?xml version="1.0" encoding="utf-8"?>
<!--
根标签为animation-list,其中oneshot代表着是否只展示一遍,设置为false会不停的循环播放动画
根标签下,通过item标签对动画中的每一个图片进行声明
android:duration 表示展示所用的该图片的时间长度
-->
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true"
>
<item android:drawable="@drawable/icon1" android:duration=""></item>
<item android:drawable="@drawable/icon2" android:duration=""></item>
<item android:drawable="@drawable/icon3" android:duration=""></item>
<item android:drawable="@drawable/icon4" android:duration=""></item>
<item android:drawable="@drawable/icon5" android:duration=""></item>
<item android:drawable="@drawable/icon6" android:duration=""></item>
</animation-list>
倒序显示动画文件:animation2.xml
<?xml version="1.0" encoding="utf-8"?>
<!--
根标签为animation-list,其中oneshot代表着是否只展示一遍,设置为false会不停的循环播放动画
根标签下,通过item标签对动画中的每一个图片进行声明
android:duration 表示展示所用的该图片的时间长度
-->
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true"
>
<item android:drawable="@drawable/icon6" android:duration=""></item>
<item android:drawable="@drawable/icon5" android:duration=""></item>
<item android:drawable="@drawable/icon4" android:duration=""></item>
<item android:drawable="@drawable/icon3" android:duration=""></item>
<item android:drawable="@drawable/icon2" android:duration=""></item>
<item android:drawable="@drawable/icon1" android:duration=""></item>
</animation-list>
第三步:上布局文件,放在res/layout目录下,文件名main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"> <ImageView android:id="@+id/animationIV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5px"
android:src="@drawable/animation1"/> <Button android:id="@+id/buttonA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5px"
android:text="顺序显示" /> <Button android:id="@+id/buttonB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5px"
android:text="停止" /> <Button android:id="@+id/buttonC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5px"
android:text="倒序显示" /> </LinearLayout>
第四步:上Activity文件,文件名:MainActivity.java
package org.shuxiang.test;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
public class Activity10 extends Activity
{
private ImageView animationIV;
private Button buttonA, buttonB, buttonC;
private AnimationDrawable animationDrawable;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.test10);
animationIV = (ImageView) findViewById(R.id.animationIV);
buttonA = (Button) findViewById(R.id.buttonA);
buttonB = (Button) findViewById(R.id.buttonB);
buttonC = (Button) findViewById(R.id.buttonC);
buttonA.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
animationIV.setImageResource(R.drawable.animation1);
animationDrawable = (AnimationDrawable) animationIV.getDrawable();
animationDrawable.start();
}
});
buttonB.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
animationDrawable = (AnimationDrawable) animationIV.getDrawable();
animationDrawable.stop();
}
});
buttonC.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
animationIV.setImageResource(R.drawable.animation2);
animationDrawable = (AnimationDrawable) animationIV.getDrawable();
animationDrawable.start();
}
});
}
}
Android 用Animation-list实现逐帧动画 (转载)的更多相关文章
- Android中实现一个简单的逐帧动画(附代码下载)
场景 Android中的逐帧动画,就是由连续的一张张照片组成的动画. 效果 注: 博客: https://blog.csdn.net/badao_liumang_qizhi 关注公众号 霸道的程序猿 ...
- 逐帧动画(Frame-by-frame Animations)
1.这一类动画可以创建一个Drawable序列,这些Drawable可以按照指定的时间间歇一个一个的显示. xml定义方法 <animation-list xmlns:android=" ...
- Android动画效果之Frame Animation(逐帧动画)
前言: 上一篇介绍了Android的Tween Animation(补间动画) Android动画效果之Tween Animation(补间动画),今天来总结下Android的另外一种动画Frame ...
- Android笔记(六十三) android中的动画——逐帧动画( frame-by-frame animation)
就好像演电影一样,播放实现准备好的图片,来实现动画效果. 逐帧动画需要用到AnimationDrawable类,该类主要用于创建一个逐帧动画,然后我们把这个动画设置为view的背景即可. androi ...
- Android 逐帧动画isRunning 一直返回true的问题
AnimationDrawabl主要通过xml实现逐帧动画,SDK实例如下: An AnimationDrawable defined in XML consists of a single < ...
- Android简单逐帧动画Frame的实现(三)
android之动画(三)通过AnimationDrawable控制逐帧动画 android与逐帧动画: 效果图: 当我们点击按钮时,该图片会不停的旋转,当再次点击按钮时,会停止在当前的状态. ...
- Android 逐帧动画
原理: 逐帧动画是最简单的一种动画.原理就是把几张图片连续显示出来,以达到动画的效果.就相当于下面这种手绘翻页动画啦~ 实现: 1.需要建立一个animation-list来设置静态图片资源.持续时间 ...
- css3 animation实现逐帧动画
css3里面的animation属性非常强大,但是自己用的比较少,最近有次面试就刚好被问到了,趁现在有时间就对animation做一个小总结.同时实现一个逐帧动画的demo作为练习 animation ...
- animation中的steps()逐帧动画
在我们平时做宽高确定,需要背景图片切换的效果时,我如果用的是一张大的png图片.而且恰好是所有小图都是从左向右排列的,那么 我们只需测量出某一个小图距左侧有多少像素(x),然后我们banckgroun ...
- Android中的动画具体解释系列【1】——逐帧动画
逐帧动画事实上非常easy,以下我们来看一个样例: <?xml version="1.0" encoding="utf-8"?> <anima ...
随机推荐
- 正則表達式--js使用案例
前言:在前端页面使用中.遇到日期格式的验证.開始使用了一款表单控件验证.可是不兼容!!并且使用起来还受到非常大约束.所以就决定自己写原生js. 为了完毕日期格式的验证.第一步,当然是学会使用正則表達式 ...
- Codeforces Round #266 (Div. 2) C. Number of Ways
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split ...
- 如何推断一个P2P平台是否靠谱?
推断一个站点,是否靠谱.是有规律可循的.P2P平台算是个新兴的电商类站点. 网上欺诈类的站点.不限于P2P,实在是太多了,真的有必要总结下最关键的几个靠谱指标. 最关键的2个 1.创始人和 ...
- 紫书p199 八数码(BFS,hash)
八数码问题 紫书上的简单搜索 渣渣好久才弄懂 #include<cstdio> #include<cstring> using namespace std; const i ...
- binary-tree-preorder-traversal——前序遍历
Given a binary tree, return the preorder traversal of its nodes' values. For example:Given binary tr ...
- GIF Movie Gear逆向实战+注册代码+补丁
GIF Movie Gear逆向实战+注册代码+补丁 准备 我是在windows 8.1 x64上进行的操作.有不足之处,还望大虾指出. 获取资源 网站下载:http://www.gamani.com ...
- adb的那点小事——360电视助手实现研究
欢迎转载,转载请注明:http://blog.csdn.net/zhgxhuaa 1. 前言 1.1. 行业背景简单介绍 当下,智能家居与智能穿戴设备无疑是继智能手机后两个最热门的方向.而智能家 ...
- MySQL中给自定义的字段查询结果添加排名的方法
我正在用 MySQL 客户端的时候,突然想到如果可以给查询结果添加排名该多好啊,然后就找到了一个简单的解决办法. 下面是一个示例表的数据: 然后我们要根据 Roll_No 字段进行排序并给出排名,我 ...
- Appium基于安卓的各种FindElement的控件定位
转自:http://www.2cto.com/kf/201410/340345.html 1. findElementByName 1.1 示例 ? 1 2 el = driver.findEleme ...
- sublime 中配置 python 运行
运行是按快捷键 ”ctrl + B“ Preferences->Browse Packages->Python->Python.sublime-build 编辑这个文件. 修改成 ...