150e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainpage.title=Animation and Graphics Overview
250e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main@jd:body
350e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main
450e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  <p>Android provides a variety of powerful APIs for applying animation to UI elements and drawing custom
550e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  2D and 3D graphics. The sections below provide an overview of the APIs and system capabilities available
650e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  and help you decide with approach is best for your needs.</p>
750e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main
850e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  <h3 id="animation">Animation</h3>
950e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  
1050e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  <p>The Android framework provides two animation systems: property animation
1150e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  (introduced in Android 3.0) and view animation. Both animation systems are viable options,
1250e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  but the property animation system, in general, is the preferred method to use, because it
1350e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  is more flexible and offers more features. In addition to these two systems, you can utilize Drawable
1450e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  animation, which allows you to load drawable resources and display them one frame after
1550e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  another.</p>
1650e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main
1750e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main<dl>
1850e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main<dt><strong><a href="{@docRoot}guide/topics/graphics/prop-animation.html">Property
1950e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott MainAnimation</a></strong></dt>
2050e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main<dd>Introduced in Android 3.0 (API level 11), the property animation system lets you
2150e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainanimate properties of any object, including ones that are not rendered to the screen. The system is
2250e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainextensible and lets you animate properties of custom types as well.</dd>
2350e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main
2450e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main<dt><strong><a href="{@docRoot}guide/topics/graphics/view-animation.html">View
2550e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott MainAnimation</a></strong></dt>
2650e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main<dd>View Animation is the older system and can only be used for Views. It is relatively easy to
2750e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainsetup and offers enough capabilities to meet many application's needs.</dd>
2850e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main</dl>
2950e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main
3050e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main<dt><strong><a href="{@docRoot}guide/topics/graphics/drawable-animation.html">Drawable
3150e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott MainAnimation</a></strong></dt>
3250e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main<dd>Drawable animation involves displaying {@link android.graphics.drawable.Drawable} resources one
3350e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainafter another, like a roll of film. This method of animation is useful if you want to animate
3450e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainthings that are easier to represent with Drawable resources, such as a progression of bitmaps.</dd>
3550e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main
3650e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main<h3 id="graphics">2D and 3D Graphics</h3>
3750e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main
3850e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main<p>When writing an application, it's important to consider exactly what your graphical demands will be.
3950e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott MainVarying graphical tasks are best accomplished with varying techniques. For example, graphics and animations
4050e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainfor a rather static application should be implemented much differently than graphics and animations
4150e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainfor an interactive game. Here, we'll discuss a few of the options you have for drawing graphics
4250e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainon Android and which tasks they're best suited for.
4350e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main</p>
4450e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main
4550e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main<dl>
4650e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main<dt><strong><a href="{@docRoot}guide/topics/graphics/2d-graphics.html">Canvas and
4750e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott MainDrawables</a></strong></dt>
4850e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main<dd>Android provides a set of {@link android.view.View} widgets that provide general functionality
4950e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainfor a wide array of user interfaces. You can also extend these widgets to modify the way they
5050e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainlook or behave. In addition, you can do your own custom 2D rendering using the various drawing
5150e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainmethods contained in the {@link android.graphics.Canvas} class or create {@link
5250e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainandroid.graphics.drawable.Drawable} objects for things such as textured buttons or frame-by-frame
5350e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainanimations.</dd>
5450e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main
5550e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main<dt><strong><a href="{@docRoot}guide/topics/graphics/hardware-accel.html">Hardware
5650e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott MainAcceleration</a></strong></dt>
5750e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main<dd>Beginning in Android 3.0, you can hardware accelerate the majority of
5850e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainthe drawing done by the Canvas APIs to further increase their performance.</dd>
5950e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main
6050e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main<dt><strong><a href="{@docRoot}guide/topics/graphics/opengl.html">OpenGL</a></strong></dt>
6150e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main<dd>Android supports OpenGL ES 1.0 and 2.0, with Android framework APIs as well as natively
6250e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainwith the Native Development Kit (NDK). Using the framework APIs is desireable when you want to add a
6350e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainfew graphical enhancements to your application that are not supported with the Canvas APIs, or if
6450e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainyou desire platform independence and don't demand high performance. There is a performance hit in
6550e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainusing the framework APIs compared to the NDK, so for many graphic intensive applications such as
6650e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Maingames, using the NDK is beneficial (It is important to note though that you can still get adequate
6750e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainperformance using the framework APIs. For example, the Google Body app is developed entirely
6850e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Mainusing the framework APIs). OpenGL with the NDK is also useful if you have a lot of native
6950e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Maincode that you want to port over to Android. For more information about using the NDK, read the
7050e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Maindocs in the <code>docs/</code> directory of the <a href="{@docRoot}tools/sdk/ndk/index.html">NDK
7150e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Maindownload.</a></dd>
7250e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main</dl>
7350e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main
74