drawable下xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:duration="500" android:drawable="@drawable/a1"/>
<item android:duration="500" android:drawable="@drawable/a2"/>
<item android:duration="500" android:drawable="@drawable/a3"/>
<item android:duration="500" android:drawable="@drawable/a4"/>
<item android:duration="500" android:drawable="@drawable/a5"/>
<item android:duration="500" android:drawable="@drawable/a6"/>
<item android:duration="500" android:drawable="@drawable/a7"/>
<item android:duration="500" android:drawable="@drawable/a8"/>
<item android:duration="500" android:drawable="@drawable/a9"/>
</animation-list>
activity
package com.zdsoft.animationdrawable0110;
import android.graphics.drawable.AnimationDrawable;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
private ImageView img;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
img = (ImageView) findViewById(R.id.img);
img.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.anim_img));
//帧动画
AnimationDrawable animationDrawable = (AnimationDrawable) img.getDrawable();
animationDrawable.start();
}
}