在 xml中 按顺序添加动画的图片 ,如果每张10k左右 最多添加15张左右 会报内存溢出的异常 所以适合少量的图片做的动画
android:oneshot="true"属性 设置是否自动播放。
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"android:oneshot="true" >
<item
android:drawable="@drawable/f1_00000" android:duration="35"/>
<item
android:drawable="@drawable/f1_00001" android:duration="35"/>
<item
android:drawable="@drawable/f1_00002"android:duration="35"/>
<item
android:drawable="@drawable/f1_00003" android:duration="35"/>
<item
android:drawable="@drawable/f1_00004" android:duration="35"/>
</animation-list>
2 在布局中应用
<ImageView
android:id="@+id/frame_image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"/>
3 java中的代码
private ImageView image;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.solofengs);
image = (ImageView) findViewById(R.id.frame_image);
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
image.setBackgroundResource(R.anim.solofeng);
AnimationDrawable anim = (AnimationDrawable) image.getBackground();
anim.start();
}