转Android 用Animation-list实现逐帧动画
第一步:先上图片素材,以下素材放到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="150"></item>
- <item android:drawable="@drawable/icon2" android:duration="150"></item>
- <item android:drawable="@drawable/icon3" android:duration="150"></item>
- <item android:drawable="@drawable/icon4" android:duration="150"></item>
- <item android:drawable="@drawable/icon5" android:duration="150"></item>
- <item android:drawable="@drawable/icon6" android:duration="150"></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="150"></item>
- <item android:drawable="@drawable/icon5" android:duration="150"></item>
- <item android:drawable="@drawable/icon4" android:duration="150"></item>
- <item android:drawable="@drawable/icon3" android:duration="150"></item>
- <item android:drawable="@drawable/icon2" android:duration="150"></item>
- <item android:drawable="@drawable/icon1" android:duration="150"></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 ...
随机推荐
- 单尺度二维离散小波分解dwt2
clc,clear all,close all; load woman; [cA,cH,cV,cD]=dwt2(X,'haar');%单尺度二维离散小波分解.分解小波函数haar figure,ims ...
- luci-bwc
文件位于: ../feeds/luci/modules/admin-full/src/luci-bwc.c 功能: Very simple bandwidth collector cache fo ...
- 与malloc有关的问题
nefu 1026 申请动态空间存放字符串,将其排序后输出 http://acm.nefu.edu.cn/JudgeOnline/problemShow.php?problem_id=1026 #in ...
- C++对象模型笔记之程序设计模型
C++程序设计模型支持三种程序设计模型 1.程序模型(procedural model) 可以理解为过程化模型,就像C一样 2.抽象数据类型模型(ADT) 数据结构教材里有说过,查了下资料也不是很明确 ...
- spring容器启动的加载过程(一)
使用spring,我们在web.xml都会配置ContextLoaderListener <listener> <listener-class> org.springframe ...
- java的string.split()分割特殊字符时注意点
[1]单个符号作为分隔符 String address="上海|上海市|闵行区|吴中路"; String[] splitAddress=address.s ...
- ajax的项目实操(只用于记录部分文件未引入)
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- C#整理 条件语句
条件语句主要分为if else语句和switch case语句. if else语句主要分为四种格式: 1. if(表达式) {} 2.二选一 if(表达式) {} else {} 3.多选一 if( ...
- JavaScript(10)——Ajax以及跨域处理
Ajax以及跨域处理 哈哈哈,终于写到最后一章了.不过也还没有结束,说,不要为了学习而学习,恩.我是为了好好学习而学习呀.哈哈哈.正在尝试爱上代码,虽然有一丢丢的难,不过,我相信我会的! [Ajax] ...
- 【第一篇】Python基础
Python学习 学习站点:https://www.shiyanlou.com/ 1 hello world code如下: $ python [15:50:40] Python2.7.6(defau ...





