Thursday, July 11, 2013

Android Animation Tutorial

We can animate all the views like Layouts, TextViews,ImageViews, Buttons etc. Animation makes the GUI  more interactive and enhance User Experience.

Android offers two kinds of animation:
Frame-by-Frame Animations are  Traditional cell-based animations in which a different Drawable
is displayed in each frame. Frame-by-frame animations are displayed within a View,
using its Canvas as a projection screen.
Tweened Animations Tweened animations are applied to Views, letting you define a series
of changes in position, size, rotation, and opacity that animate the View contents.


Note: Both animation types are restricted to the original bounds of the View they’re  applied to.   Rotations, translations, and scaling transformations that extend beyond
the original boundaries of the View will result in the contents being clipped.


 Tweened Animations

Tweened animations offer a simple way to provide depth, movement, or feedback to your users at a
minimal resource cost.
Using animations to apply a set of orientation, scale, position, and opacity changes is much less
resource-intensive than manually redrawing the Canvas to achieve similar effects, not to mention far
simpler to implement.

Tweened animations are commonly used to:
➤ Transition between Activities.
➤ Transition between layouts within an Activity.
➤ Transition between different content displayed within the same View.
➤ Provide user feedback such as:
➤ Indicating progress.
➤ ‘‘Shaking’’ an input box to indicate an incorrect or invalid data entry.
Creating Tweened Animations
Tweened animations are created using the Animation class. The following list explains the animation
types available.
➤ AlphaAnimation Lets you animate a change in the View’s transparency (opacity or alpha
blending).
➤ RotateAnimation Lets you spin the selected View canvas in the XY plane.
➤ ScaleAnimation Allows you to zoom in to or out from the selected View.
➤ TranslateAnimation Lets you move the selected View around the screen (although it will
only be drawn within its original bounds).

Android offers the AnimationSet class to group and configure animations to be run as a set. You can
define the start time and duration of each animation used within a set to control the timing and order
of the animation sequence.
It’s important to set the start offset and duration for each child animation, or they will all start and complete at the same time.

Animating Layouts and View Groups

A LayoutAnimation is used to animate View Groups, applying a single Animation (or Animation Set)
to each child View in a predetermined sequence.
Use a LayoutAnimationController to specify an Animation (or Animation Set) that’s applied to each
child View in a View Group. Each View it contains will have the same animation applied, but you can
use the Layout Animation Controller to specify the order and start time for each View.
Android includes two LayoutAnimationController classes.
LayoutAnimationController Lets you select the start offset of each View (in milliseconds)
and the order (forward, reverse, and random) to apply the animation to each child View.
GridLayoutAnimationController Is a derived class that lets you assign the animation
sequence of the child Views using grid row and column references.


Following are Examples of Animating diffrent types of Views

Android Animation Examples:


Animating  ImageViews




Layout Animations

No comments:

Post a Comment