本文实例为大家分享了利用animation-list实现帧动画的具体代码,供大家参考,具体内容如下
将要顺序播放的图片放在资源目录下
再drawable目录下新建animation1文件和animation2文件 一个是按顺序显示动画,一个是倒序显示动画,
顺序显示动画文件:animation1.xml
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true"
>
倒序显示动画文件:animation2.xml
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true"
>
布局文件
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5px"
android:src="@drawable/animation1"/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5px"
android:text="顺序显示" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5px"
android:text="停止" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5px"
android:text="倒序显示" />
Activity文件
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();
}
});
}
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持找一找教程网。