AnimationDrawable

The AnimationDrawable is how you define a frame-by-frame animation in Android. It describes a drawable as a list of other drawable resources that are played sequentially to create an animation. This is an animation in the most traditional sense: a sequence of independent images, played one after another.

We can define the frames of an animation in code using the AnimationDrawable class, but it is much easier to use XML. This file lists the frames that compose the animation and their duration. The XML is composed by a root node of the <animation-list> type and a series of child nodes of the <item> type that define a frame using a drawable resource and the frame duration:

<?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" ...

Get Android Game Programming: A Developer’s Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.