Android帧动画笔记

创建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/progress_1"
android:duration="200"/>
<item
android:drawable="@drawable/progress_2"
android:duration="200"/>
<item
android:drawable="@drawable/progress_3"
android:duration="200"/>
<item
android:drawable="@drawable/progress_4"
android:duration="200"/>
<item
android:drawable="@drawable/progress_5"
android:duration="200"/>
<item
android:drawable="@drawable/progress_6"
android:duration="200"/>
<item
android:drawable="@drawable/progress_7"
android:duration="200"/>
<item
android:drawable="@drawable/progress_8"
android:duration="200"/>

</animation-list>

在布局文件中引用:
<ImageView
android:id="@+id/iv_progress"
android:src="@drawable/progress_anim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

编写代码:
public class ProgressAnimDemo extends AppCompatActivity {
private ImageView iv_progress;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_progressanimdemo);
iv_progress = (ImageView) findViewById(R.id.iv_progress);
//获取AnimationDrawable对象,xml如果是通过background设置drawable则通过getDrwaable(),如果是src则通过getDrawable
AnimationDrawable anim = (AnimationDrawable)iv_progress.getDrawable();
anim.start();//启动帧动画
}
}
效果:

 
 
posted @ 2016-12-05 19:42  Epilogue  阅读(103)  评论(0编辑  收藏  举报