在Android中,可以使用AnimationDrawable类来实现循环播放动画。AnimationDrawable是一个Drawable的子类,可以用来定义一系列的帧动画,然后将其设置给一个ImageView来播放。
以下是实现循环播放动画的步骤:
在res/drawable文件夹下创建一个xml文件,用来定义帧动画的每一帧。例如,创建一个anim.xml文件:<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false"> <item android:drawable="@drawable/frame1" android:duration="100"/> <item android:drawable="@drawable/frame2" android:duration="100"/> <item android:drawable="@drawable/frame3" android:duration="100"/> <!-- 添加更多的帧 --></animation-list>在代码中加载这个动画并设置给ImageView播放:// 加载帧动画AnimationDrawable animation = (AnimationDrawable) getResources().getDrawable(R.drawable.anim);// 设置循环播放animation.setOneShot(false);// 将动画设置给ImageViewimageView.setImageDrawable(animation);// 开始播放动画animation.start();通过上述步骤,就可以在Android应用中实现循环播放动画。




