在Android的动画中有一种叫做Frame by Frame 的动画效果,就是跟Flash播放一样,是一帧一帧地显示,如果动画是连续并且有规律的话,就跟播放视频一样。

首先在drawable目录下添加anim_nv.xml文件,添加需要显示的图片和间隔时间

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/psb1"
android:duration="500"/>
<item android:drawable="@drawable/psb2"
android:duration="500"/>
<item android:drawable="@drawable/psb3"
android:duration="500"/>
<item android:drawable="@drawable/psb4"
android:duration="500"/> </animation-list>

布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" /> <Button
android:id="@+id/alpha"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="动画效果演示"/> <ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dip"/> </LinearLayout>

在Activity中

package com.example.animation;

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView; import com.example.widgetdemo.R; public class AnimationXmlDemo3 extends Activity {
private Button alpha = null;
private ImageView image = null; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.animation_xml3);
alpha = (Button) findViewById(R.id.alpha);
image = (ImageView) findViewById(R.id.image); alpha.setOnClickListener(new alphaListener());
} class alphaListener implements OnClickListener { @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
//为图片添加图片背景
image.setBackgroundResource(R.drawable.anim_nv);
AnimationDrawable animationDrawable = (AnimationDrawable) image
.getBackground();
animationDrawable.start();
} }
}

这样一个连续显示图片的效果就完成了。

源码下载:

点击打开链接

Android常用动画Frame-By-Frame Animations的使用的更多相关文章

  1. Android 常用动画

    一.动画类型 Android的animation由四种类型组成:alpha.scale.translate.rotate XML配置文件中 alpha :渐变透明度动画效果 scale :渐变尺寸伸缩 ...

  2. Android 常用动画之RotateAnimation

    前两天接到任务做一个UI,有用到动画,于是抽空看了下Android动画相关知识. Android Animation共有四大类型,分别是 Alpha      透明度动画 Scale      大小伸 ...

  3. Android常用动画alpha和rotate同时使用

    Android的动画可以是一种动画,也可以多种动画作用于一张图片上,如RotaeAnimation和AlphaAnimation同时放到一个配置文件中 alpha1.xml <?xml vers ...

  4. Android Animation 动画Demo(Frame帧动画)

    上一页介绍Animation动画第一:Tween吐温动画. 本文介绍了以下Animation也有动画的形式:Frame帧动画. Frame动画是一系列照片示出的顺序按照一定的处理,和机制,以放电影很阶 ...

  5. Android常用动画Animation的使用

    Andriod中有几种常用的Animation AlphaAnimation  淡入淡出效果 RotateAnimation 旋转效果 ScaleAnimation 缩放动画 TranslaAnima ...

  6. Android 常用动画小结

    1. 渐入动画 // Request the next activity transition (here starting a new one). startActivity(new Intent( ...

  7. Android动画效果之Frame Animation(逐帧动画)

    前言: 上一篇介绍了Android的Tween Animation(补间动画) Android动画效果之Tween Animation(补间动画),今天来总结下Android的另外一种动画Frame ...

  8. Android 动画具体解释Frame动画 (Drawable Animation)

    Frame动画像gif画画,通过一些静态的图片,以实现动画效果. Android sdk该AnimationDrawable就是专门针对Frame动画,当然Frame动画也可在java代码或者xml中 ...

  9. Android 属性动画 源码解析 深入了解其内部实现

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/42056859,本文出自:[张鸿洋的博客] 我参加了博客之星评选,如果你喜欢我的博 ...

随机推荐

  1. Sublime Text2

    Ctrl+L选择整行(按住-继续选择下行) Ctrl+KK 从光标处删除至行尾 Ctrl+Shift+K 删除整行 Ctrl+Shift+D 复制光标所在整行,插入在该行之前 Ctrl+J 合并行(已 ...

  2. Delphi的MDI编程中遇到的一个奇怪问题(值得研究的一个问题)

    近日在用delphi写一个多文档应用程序,除了一个主界面是自动生成的,其他功能页面全部都是通过Application.CreateForm()动态生成的,也就是说在ProjectManager中点击程 ...

  3. QT全局热键(用nativeKeycode封装API,不跨平台)

    在网上找了很长时间,大家都提到了一个QT全局热键库(qxtglobalshortcut),支持跨平台.在这篇文章中,我将只展示出windows平台下全局热键的设置. 这里提供的方法是在MyGlobal ...

  4. HDU 1130 How Many Trees?

    裸的卡特兰数 C++#include<iostream> #include<cstdio> using namespace std; #define base 10000 #d ...

  5. 让自己的apk可以被别人用二维码下载

    通过二维码下载的流程是, 1.截获地址当有一个url被二维码扫描后的被截获,请先确认能够被截获. 2.接受intent无论是把这个消息的地址发送给activity,还是reciver,都要进入到你的程 ...

  6. BZOJ3231(矩阵连乘,稍有点复杂)

    题目:3231: [Sdoi2008]递归数列 题意: 一个由自然数组成的数列按下式定义:   对于i <= k:ai = bi 对于i > k: ai = c1ai-1 + c2ai-2 ...

  7. hdu1003 1024 Max Sum&Max Sum Plus Plus【基础dp】

    转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4302208.html   ---by 墨染之樱花 dp是竞赛中常见的问题,也是我的弱项orz, ...

  8. SQL中的Update、delete与inner join 联合使用

    Update XXX set XXX where 这种写法大家肯定都知道,才发现update和delete居然支持inner join的update方式,太神奇了. update的格式是 update ...

  9. windows上运行npm Error: ENOENT, stat 'C:\Users\

    node 中 npm报错 Error: ENOENT, stat C:\Users\Administrator\AppData\Roaming\npm 报错原因可能是修改了node的默认安装路径.于是 ...

  10. HtmlUnit+Jsoup 解决爬虫无法解析执行javascript的问题

    本人最近在研究爬虫.作为一个新手.研究了些爬虫框架,发现所有开源的爬虫框架很多,功能也很齐全,但唯独遗憾的是,目前还没有发现那个爬虫对js完美的解释并执行.看了浅谈网络爬虫爬js动态加载网页(二)之后 ...