您可以使用放在名为first.png,second.png等的drawable文件夹中的不同图像帧来制作动画效果,并在一定时间间隔后加载它。
创建animation_list.xml并把它。
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/first" android:duration="210" />
<item android:drawable="@drawable/second" android:duration="210" />
<item android:drawable="@drawable/third" android:duration="210" />
<item android:drawable="@drawable/fourth" android:duration="210" />
<item android:drawable="@drawable/fifth" android:duration="210" />
<item android:drawable="@drawable/sixth" android:duration="210" />
</animation-list>
然后在 MainActivity 代码中 is.create imageview 在activity_main xml中命名为yourImageView
import android.os.Bundle;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.widget.ImageView;
public class MainActivity extends Activity {
private AnimationDrawable frameAnimation;
private ImageView view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Type casting the Image View
view = (ImageView) findViewById(R.id.yourImageView);
// Setting animation_list.xml as the background of the image view
view.setBackgroundResource(R.drawable.animation_list);
// Type casting the Animation drawable
frameAnimation = (AnimationDrawable) view.getBackground();
frameAnimation.start();
}
}