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();
}
}
}
完成!