它被称为逐帧动画,由一系列Drawable对象定义,可用作View对象的背景。您可以找到详细信息here。有样品代码在下面发布。 1 sec
的持续时间以毫秒为单位,您必须将其作为1000
。在res /绘制/文件夹
spin_animation.xml文件:
<animation-list android:id="@+id/selected" android:oneshot="false">
<item android:drawable="@drawable/wheel0" android:duration="50" />
<item android:drawable="@drawable/wheel1" android:duration="50" />
<item android:drawable="@drawable/wheel2" android:duration="50" />
<item android:drawable="@drawable/wheel3" android:duration="50" />
<item android:drawable="@drawable/wheel4" android:duration="50" />
<item android:drawable="@drawable/wheel5" android:duration="50" />
</animation-list>
这里是加载和播放这个动画的代码。
// Load the ImageView that will host the animation and
// set its background to our AnimationDrawable XML resource.
ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image);
img.setBackgroundResource(R.drawable.spin_animation);
// Get the background, which has been compiled to an AnimationDrawable object.
AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
// Start the animation (looped playback by default).
frameAnimation.start();
,并停止动画
frameAnimation.stop();
非常感谢你。 它帮了我 – mariya 2015-02-23 15:14:54
快乐地帮助玛丽亚:)。 – 2015-02-23 15:17:39
谢谢...点击一个按钮后,这个过程可以停止吗? – mariya 2015-02-23 15:24:40