android AnimationDrawable的使用

来源:互联网 发布:最强围棋软件 编辑:程序博客网 时间:2024/05/17 04:30

 

 一个对象用于创建动画帧的帧,通过一系列Drawable对象定义,它可以用来作为一个视图对象的背景。

 

一个对象用于创建动画帧的帧,通过一系列Drawable对象定义,它可以用来作为一个视图对象的背景。

创建帧动画帧是在一个XML定义动画的最简单的方法文件,放在res/drawable/文件夹,并将它设置为一个视图对象的背景。然后,调用 start()运行动画。

定义一个AnimationDrawable在XML组成一个单一的<动画列表>元,和一系列嵌套的标签。每个项目定义了一个帧动画。请看下面的例子。

在res/drawable/文件夹spin_animation.xml文件:

<!-- Animation frames are wheel0.png -- wheel5.png files inside the res/drawable/ folder --> <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();
 
android:drawable 参考使用框架drawable资源。android:duration 时间(毫秒)来显示这个框架。android:oneshot 如果TRUE,该动画将只运行一次,然后停止。android:variablePadding 如果是真的,允许的填料可变化的基础上的目前的状态,选择。android:visible 可提供的默认初始可见性状态;值为false。


android:drawable 参考使用框架drawable资源。android:duration 时间(毫秒)来显示这个框架。android:oneshot 如果TRUE,该动画将只运行一次,然后停止。android:variablePadding 如果是真的,允许的填料可变化的基础上的目前的状态,选择。android:visible 可提供的默认初始可见性状态;值为false。


具体使用参考文档