IT. Expert System.

Android Reference

AnimationDrawable


android.graphics.drawable

Class AnimationDrawable

  • All Implemented Interfaces:
    Animatable, Drawable.Callback, Runnable


    public class AnimationDrawable
    extends DrawableContainer
    implements Runnable, Animatable
    An object used to create frame-by-frame animations, defined by a series of Drawable objects, which can be used as a View object's background.

    The simplest way to create a frame-by-frame animation is to define the animation in an XML file, placed in the res/drawable/ folder, and set it as the background to a View object. Then, call start() to run the animation.

    An AnimationDrawable defined in XML consists of a single <animation-list> element, and a series of nested <item> tags. Each item defines a frame of the animation. See the example below.

    spin_animation.xml file in res/drawable/ folder:

    <!-- 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>

    Here is the code to load and play this animation.

     // 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();
     

    Developer Guides

    For more information about animating with AnimationDrawable, read the Drawable Animation developer guide.

    • Constructor Detail

      • AnimationDrawable

        public AnimationDrawable()
    • Method Detail

      • setVisible

        public boolean setVisible(boolean visible,
                         boolean restart)
        Description copied from class: Drawable
        Set whether this Drawable is visible. This generally does not impact the Drawable's behavior, but is a hint that can be used by some Drawables, for example, to decide whether run animations.
        Overrides:
        setVisible in class DrawableContainer
        Parameters:
        visible - Set to true if visible, false if not.
        restart - You can supply true here to force the drawable to behave as if it has just become visible, even if it had last been set visible. Used for example to force animations to restart.
        Returns:
        boolean Returns true if the new visibility is different than its previous state.
      • stop

        public void stop()

        Stops the animation. This method has no effect if the animation is not running.

        Specified by:
        stop in interface Animatable
        See Also:
        isRunning(), start()
      • isRunning

        public boolean isRunning()

        Indicates whether the animation is currently running or not.

        Specified by:
        isRunning in interface Animatable
        Returns:
        true if the animation is running, false otherwise
      • run

        public void run()

        This method exists for implementation purpose only and should not be called directly. Invoke start() instead.

        Specified by:
        run in interface Runnable
        See Also:
        start()
      • getNumberOfFrames

        public int getNumberOfFrames()
        Returns:
        The number of frames in the animation
      • getFrame

        public Drawable getFrame(int index)
        Returns:
        The Drawable at the specified frame index
      • getDuration

        public int getDuration(int i)
        Returns:
        The duration in milliseconds of the frame at the specified index
      • isOneShot

        public boolean isOneShot()
        Returns:
        True of the animation will play once, false otherwise
      • setOneShot

        public void setOneShot(boolean oneShot)
        Sets whether the animation should play once or repeat.
        Parameters:
        oneShot - Pass true if the animation should only play once
      • addFrame

        public void addFrame(Drawable frame,
                    int duration)
        Add a frame to the animation
        Parameters:
        frame - The frame to add
        duration - How long in milliseconds the frame should appear
      • mutate

        public Drawable mutate()
        Description copied from class: Drawable
        Make this drawable mutable. This operation cannot be reversed. A mutable drawable is guaranteed to not share its state with any other drawable. This is especially useful when you need to modify properties of drawables loaded from resources. By default, all drawables instances loaded from the same resource share a common state; if you modify the state of one instance, all the other instances will receive the same modification. Calling this method on a mutable Drawable will have no effect.
        Overrides:
        mutate in class DrawableContainer
        Returns:
        This drawable.
        See Also:
        Drawable.ConstantState, Drawable.getConstantState()


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 794 / 96289597. Delta: 0.04040 с