三、Frame-byFrame动画
Activity代码:
public class AnimationFrameByFrameActivity extends Activity {
private ImageView img=null;
private Button btn=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
img=(ImageView)findViewById(R.id.img);
btn=(Button)findViewById(R.id.btn);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//逐帧动画效果
// TODO Auto-generated method stub
img.setBackgroundResource(R.drawable.animimg);
AnimationDrawable anim=(AnimationDrawable)img.getBackground();
anim.start();
}
});
}
}
Animimg.xml代码:
<?xmlversion="1.0"encoding="utf-8"?>
<animation-listxmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<itemandroid:drawable="@drawable/a"android:duration="500"/>
<itemandroid:drawable="@drawable/b"android:duration="500"/>
<itemandroid:drawable="@drawable/c"android:duration="500"/>
<itemandroid:drawable="@drawable/d"android:duration="500"/>
</animation-list>