android帧动画
 最后更新 2021-03-02 15:08 星期二  所属:
	    安卓教程  浏览:1227
	
一、在xml文件中设定帧动画
1、最先得在drawable資源文件夹名称下建立一个animation_list文档
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:drawable="@drawable/p1"
        android:duration="500" />
    <item
        android:drawable="@drawable/p2"
        android:duration="500" />
    <item
        android:drawable="@drawable/p3"
        android:duration="500" />
    <item
        android:drawable="@drawable/p4"
        android:duration="500" />
    <item
        android:drawable="@drawable/p5"
        android:duration="500" />
</animation-list>
2、根据java编码运行将动漫载入到室内空间中,并运行
ImageView imageView=(ImageView)findViewById(R.id.id_iv); imageView.setImageResource(R.drawable.anim_list); AnimationDrawable animationDrawable = (AnimationDrawable) image.getDrawable(); animationDrawable.setOneShot(false);//是不是只实行一次 animationDrawable.start();//打开动漫 //animationDrawable.stop();//终止动漫
二、在java编码中设定帧动画
ImageView imageView= (ImageView)findViewById(R.id.id_iv); animationDrawable= new AnimationDrawable(); animationDrawable.addFrame(getResources().getDrawable(R.drawable.p1), 500); animationDrawable.addFrame(getResources().getDrawable(R.drawable.p2), 500); imageView.setImageDrawable(animationDrawalbe); animationDrawable.setOneShot(false);//是不是只实行一次 animationDrawable.start();//打开动漫 //animationDrawable.stop();//终止动漫
