`

android 逐帧动画

 
阅读更多

android 逐帧动画 研究了一下下,超简单。一步步按照我流程来弄!

创建一个android项目test.

一:在res创建一个anim文件夹,该文件夹下创建firefox_animation.xml文件

代码如下

<?xml version="1.0" encoding="utf-8"?>  

<animation-list       
    xmlns:android="http://schemas.android.com/apk/res/android"     
    android:oneshot="false">
 
		
		<item android:duration="300" android:drawable="@drawable/sound_2" /> 
		<item android:duration="300" android:drawable="@drawable/sound_3" /> 
		<item android:duration="300" android:drawable="@drawable/sound_4" /> 
		<item android:duration="300" android:drawable="@drawable/sound_5" /> 
		<item android:duration="300" android:drawable="@drawable/sound_6" /> 
		<item android:duration="300" android:drawable="@drawable/sound_7" /> 
		<item android:duration="300" android:drawable="@drawable/sound_8" /> 
		<item android:duration="300" android:drawable="@drawable/sound_9" /> 
		<item android:duration="300" android:drawable="@drawable/sound_10" /> 
		<item android:duration="300" android:drawable="@drawable/sound_11" /> 
		<item android:duration="300" android:drawable="@drawable/sound_12" /> 
		<item android:duration="300" android:drawable="@drawable/sound_13" /> 
		<item android:duration="300" android:drawable="@drawable/sound_14" /> 
		<item android:duration="300" android:drawable="@drawable/sound_15" /> 
		<item android:duration="300" android:drawable="@drawable/sound_16" /> 
		<item android:duration="300" android:drawable="@drawable/sound_17" /> 
		<item android:duration="300" android:drawable="@drawable/sound_18" /> 
		<item android:duration="300" android:drawable="@drawable/sound_19" /> 
		<item android:duration="300" android:drawable="@drawable/sound_20" /> 
		<item android:duration="300" android:drawable="@drawable/sound_21" /> 
		<item android:duration="300" android:drawable="@drawable/sound_22" /> 
		<item android:duration="300" android:drawable="@drawable/sound_23" /> 
		<item android:duration="300" android:drawable="@drawable/sound_24" /> 
		<item android:duration="300" android:drawable="@drawable/sound_25" />
		<item android:duration="300" android:drawable="@drawable/sound_26" />
		<item android:duration="300" android:drawable="@drawable/sound_27" />
		<item android:duration="300" android:drawable="@drawable/sound_28" />
		<item android:duration="300" android:drawable="@drawable/sound_29" />
		<item android:duration="300" android:drawable="@drawable/sound_30" />
		<item android:duration="300" android:drawable="@drawable/sound_31" />
		<item android:duration="300" android:drawable="@drawable/sound_32" />  
		              
</animation-list>

 二:在main.xml代码如下

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="wrap_content" android:layout_height="wrap_content"
	android:orientation="vertical">



	<ImageView android:id="@+id/imageview1" android:layout_width="100px"
		android:layout_height="100px" android:src="@anim/firefox_animation">
	</ImageView>

	<Button android:id="@+id/start" android:layout_width="fill_parent"
		android:layout_height="wrap_content" android:text="Start">
	</Button>

	<Button android:id="@+id/start_once" android:layout_width="fill_parent"
		android:layout_height="wrap_content" android:text="Start_once">
	</Button>
</LinearLayout>

 三:在MianActivity中代码

package com.test;

import android.app.Activity;
import android.os.Bundle;

import android.graphics.drawable.AnimationDrawable;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

public class MainA extends Activity {
    private AnimationDrawable draw = null;
    private Button start = null;
    private Button startOnce = null;
    private boolean isoneshot = true;
    
    public void onCreate(Bundle bundle)
    {
     super.onCreate(bundle);
     this.setContentView(R.layout.main);
     ImageView view = (ImageView)findViewById(R.id.imageview1);
     draw = (AnimationDrawable)view.getDrawable();
     start = (Button)findViewById(R.id.start);
     start.setOnClickListener(new OnClickListener()
     {
      public void onClick(View v) {
       // TODO Auto-generated method stub
       startAnimation();
      }
     });
     startOnce = (Button)findViewById(R.id.start_once);
     startOnce.setOnClickListener(new OnClickListener()
     {

      public void onClick(View v) {
       // TODO Auto-generated method stub
       if(isoneshot)
       {
        startOnce.setText("startOnce");
       }
       else
       {
        startOnce.setText("Play Repace");
       }
       draw.setOneShot(isoneshot);
       isoneshot = !isoneshot;
      }
      
     });
    }
    
    private void startAnimation()
    {
     if(draw.isRunning())
     {
      draw.stop();
     }
     else
     {
      draw.stop();
      draw.start();
     }
    }
   }

 

完成!

3
0
分享到:
评论

相关推荐

    android逐帧动画

    在这个特定的案例中,我们看到标题为“android逐帧动画”,描述提到有三张图片进行切换,每帧持续时间为50毫秒。这个例子展示了如何在Android应用中实现这种基本的动画效果。 首先,我们需要了解Android中的`...

    android 逐帧动画实现 源码

    在Android开发中,逐帧动画是一种常见的动画效果,它通过连续播放一系列静态图像来创造出动态效果,类似于传统的电影制作方式。本源码着重探讨如何在Android应用中实现逐帧动画。 首先,我们要了解Android中的两种...

    Android 逐帧动画源码.zip

    在Android应用开发中,逐帧动画是一种常见的动画形式,它通过连续播放一系列静态图像来创造出动态效果,类似于传统的动画制作过程。"Android 逐帧动画源码.zip" 提供了一个项目实例,帮助开发者深入理解这一技术。这...

    Android逐帧动画源码.zip

    这个"Android逐帧动画源码.zip"文件包含了一个关于如何在Android应用中实现逐帧动画的示例项目,这对于开发者来说是宝贵的参考资料。 逐帧动画在Android中的实现主要依赖于`Animation`类家族,尤其是`Frame...

    Android 逐帧动画源码.rar

    在Android应用开发中,逐帧动画是一种常见的动画形式,它通过连续播放一系列静态图像来创造出动态效果。这个"Android 逐帧动画源码.rar"压缩包包含了一个关于如何实现这种动画方式的源代码示例。下面,我们将深入...

    Android 逐帧动画源码.zip源码资源下载

    在Android开发中,逐帧动画是一种常见的动画效果,它通过连续播放一系列静态图像来创造出动态效果,类似于传统的电影制作方式。本资源包“Android 逐帧动画源码.zip”提供了实现这种动画效果的源代码,适合对Android...

    Android 逐帧动画源码-IT计算机-毕业设计.zip

    在Android平台上,逐帧动画是一种常见的视觉效果,用于创建连续的动态画面,类似于电影胶片。这个"Android 逐帧动画源码"是为毕业设计准备的开发示例,可以帮助学生深入理解Android应用的开发过程,并为撰写相关论文...

    Android程序研发源码Android 逐帧动画源码.zip

    本资源"Android程序研发源码Android 逐帧动画源码.zip"提供了一个名为"AnimationDemo"的示例项目,旨在帮助开发者深入理解并实践Android中的逐帧动画技术。 首先,我们要明白逐帧动画的基本原理。逐帧动画是通过...

    Android 逐帧动画源码.zip项目安卓应用源码下载

    在Android平台上,逐帧动画是一种常见的动画实现方式,它通过连续播放一系列静态图像来创造出动态效果,类似于传统的电影制作原理。本项目“Android 逐帧动画源码.zip”提供了具体的实现示例,对于学生毕业设计、...

    Android 逐帧动画示例

    在Android中,逐帧动画可以通过`AnimationDrawable`类来实现。`AnimationDrawable`是一个可绘制对象,可以作为视图的背景,并且可以像动画一样顺序播放其包含的帧。以下将详细介绍如何创建和使用逐帧动画。 首先,...

    Android 逐帧动画的小例子

    首先,我们要理解Android中的逐帧动画。在Android中,帧动画(Frame Animation)是一种简单易用的动画形式,它通过连续播放一系列静态图像(帧)来创造出动画效果。这些帧通常保存为图片资源(如PNG或JPEG),然后在...

    Android逐帧(Frame)动画

    本篇文章将深入探讨Android逐帧动画的概念、实现方式以及相关的实践技巧。 逐帧动画的工作原理类似于传统的电影制作,通过连续播放多张图片来产生连续的动作。在Android中,这可以通过`AnimationDrawable`类来实现...

Global site tag (gtag.js) - Google Analytics