This is a mirror of official site: http://jasper-net.blogspot.com/

Android Animations - Tutorial

| Wednesday, July 6, 2011
Lars Vogel

Version 1.2
Copyright © 2011 Lars Vogel
04.07.2011

Table of Contents

1. Android Animations
1.1. Overview
1.2. Tweened Animations
1.3. Android Basics
2. Example
3. Thank you
4. Questions and Discussion
5. Links and Literature
5.1. Source Code
5.2. Android Resources
5.3. vogella Resources


1. Android Animations
1.1. Overview

Android supports two types of animations: Tweened Animations and Frame-by-frame animations.

Tweened animations are applied to Views and transform them in size, position or opacity. For example you can fade in a view or rotate him. Tweened animations are considered to be relatively unexpensive operations.

Frame-by-frame animations shows different drawables in a View. Both animations are limited to the original size of the view.
1.2. Tweened Animations

Tweened animations are instances of the abstract class "Animation". You have pre-defined Animations via the Java classes AlphaAnimation, RotateAnimation, ScaleAnimation and TranslateAnimation.

Tweened animations can be applied to the layout or directly to a view. If the animation is applied to a layout when this animation is executed whenever a view is added or removed from the layout. If an animation is added to a view you have to start the animation via your code. If you apply an animation to an layout you use the class "LayoutAnimationController".

You can group animations in "AnimationSet" in which you define the start time, duration and offsets of each animation.

You apply the animation to a view via view.startAnimation() passing the AnimationSet as a parameter. Per default a AnimationSet will run once, unless you use setRepeatModel() and setRepeastCount(). After a tweened animation finish the view returns to its original state. To change the view after the animation register an "Animation.AnimationListener" to react to the animation. This listener is notified when an animation starts or ends. Here you can change the view to this final state, e.g. make it invisible after a fade-out animation.

Animations can be defined via XMl resource files in the directory "res/anim" or via code. You can load the resource file via AnimationUtils.loadAnimiation(this,R.anim.Animation).

Per default the animation will have the same speed in getting applied. You can change this via an "Interpolator" class. This class can control the speed of the animation. You have several default classes, e.g. AccelerateInterpolator, DecelerateInterpolator, LinearInterpolator, BounceInterpolator, OvershootInterpolator and CycleInterpolator. For example the BounceInterpolator gives an bouncing effect once the animation is almost over. Please check the Javadoc for the rest of the Interpolator classes.
1.3. Android Basics

The following assumes that you have already basic knowledge in Android development . Please check the Android development tutorial to learn the basics.


Read more: Lars Vogel
QR: article.html

Posted via email from Jasper-net

0 comments: