SlideShare ist ein Scribd-Unternehmen logo
1 von 5
Chapter 17
Animation in Android
By
Dr. Ramkumar Lakshminarayanan
Introduction
Android provides a variety of powerful APIs for applying animation to UI elements
and drawing custom 2D and 3D graphics. This unit provide an overview of the APIs and
system capabilities available and help you decide with approach is best.
Animation
The Android framework provides two animation systems: property animation
(introduced in Android 3.0) and view animation. Both animation systems are viable options,
but the property animation system, in general, is the preferred method to use, because it is
more flexible and offers more features. In addition to these two systems, you can utilize
Drawable animation, which allows you to load drawable resources and display them one
frame after another.
Property Animation
Introduced in Android 3.0 (API level 11), the property animation system lets you
animate properties of any object, including ones that are not rendered to the screen. The
system is extensible and lets you animate properties of custom types as well.
View Animation
View Animation is the older system and can only be used for Views. It is relatively
easy to setup and offers enough capabilities to meet many application's needs.
Drawable Animation
Drawable animation involves displaying Drawable resources one after another, like a
roll of film. This method of animation is useful if you want to animate things that are easier
to represent with Drawable resources, such as a progression of bitmaps.
2D and 3D Graphics
When writing an application, it's important to consider exactly what your graphical
demands will be. Varying graphical tasks are best accomplished with varying techniques. For
example, graphics and animations for a rather static application should be implemented much
differently than graphics and animations for an interactive game. Here, we'll discuss a few of
the options you have for drawing graphics on Android and which tasks they're best suited for.
Canvas and Drawables
Android provides a set of View widgets that provide general functionality for a wide
array of user interfaces. You can also extend these widgets to modify the way they look or
behave. In addition, you can do your own custom 2D rendering using the various drawing
methods contained in the Canvas class or create Drawable objects for things such as textured
buttons or frame-by-frame animations.
Hardware Acceleration
Beginning in Android 3.0, you can hardware accelerate the majority of the drawing
done by the Canvas APIs to further increase their performance.
OpenGL
Android supports OpenGL ES 1.0 and 2.0, with Android framework APIs as well as
natively with the Native Development Kit (NDK). Using the framework APIs is desireable
when you want to add a few graphical enhancements to your application that are not
supported with the Canvas APIs, or if you desire platform independence and don't demand
high performance. There is a performance hit in using the framework APIs compared to the
NDK, so for many graphic intensive applications such as games, using the NDK is beneficial.
OpenGL with the NDK is also useful if you have a lot of native code that you want to port
over to Android.
Property Animation
The property animation system is a robust framework that allows you to animate
almost anything. You can define an animation to change any object property over time,
regardless of whether it draws to the screen or not. A property animation changes a property's
(a field in an object) value over a specified length of time. To animate something, you specify
the object property that you want to animate, such as an object's position on the screen, how
long you want to animate it for, and what values you want to animate between.
The property animation system lets you define the following characteristics of an animation:
ď‚· Duration: You can specify the duration of an animation. The default length is 300 ms.
ď‚· Time interpolation: You can specify how the values for the property are calculated as
a function of the animation's current elapsed time.
ď‚· Repeat count and behavior: You can specify whether or not to have an animation
repeat when it reaches the end of a duration and how many times to repeat the
animation. You can also specify whether you want the animation to play back in
reverse. Setting it to reverse plays the animation forwards then backwards repeatedly,
until the number of repeats is reached.
ď‚· Animator sets: You can group animations into logical sets that play together or
sequentially or after specified delays.
ď‚· Frame refresh delay: You can specify how often to refresh frames of your animation.
The default is set to refresh every 10 ms, but the speed in which your application can
refresh frames is ultimately dependent on how busy the system is overall and how fast
the system can service the underlying timer.
First, let's go over how an animation works with a simple example. Figure 17.1
depicts a hypothetical object that is animated with its x property, which represents its
horizontal location on a screen. The duration of the animation is set to 40 ms and the distance
to travel is 40 pixels. Every 10 ms, which is the default frame refresh rate, the object moves
horizontally by 10 pixels. At the end of 40ms, the animation stops, and the object ends at
horizontal position 40. This is an example of an animation with linear interpolation, meaning
the object moves at a constant speed.
Figure 17.1 Linear Animation
You can also specify animations to have a non-linear interpolation. Figure 17.2
illustrates a hypothetical object that accelerates at the beginning of the animation, and
decelerates at the end of the animation. The object still moves 40 pixels in 40 ms, but non-
linearly. In the beginning, this animation accelerates up to the halfway point then decelerates
from the halfway point until the end of the animation. As Figure 17.2 shows, the distance
traveled at the beginning and end of the animation is less than in the middle.
Figure 17.2 Non-linear Animation
Let's take a detailed look at how the important components of the property animation
system would calculate animations like the ones illustrated above. Figure 17.3 depicts how
the main classes work with one another.
Figure 17.3 Animation Calculation
The ValueAnimator object keeps track of your animation's timing, such as how long
the animation has been running, and the current value of the property that it is animating.
The ValueAnimator encapsulates a TimeInterpolator, which defines animation
interpolation, and a TypeEvaluator, which defines how to calculate values for the property
being animated. For example, in Figure 17.2, the TimeInterpolator used would
be AccelerateDecelerateInterpolator and the TypeEvaluator would be IntEvaluator.
To start an animation, create a ValueAnimator and give it the starting and ending
values for the property that you want to animate, along with the duration of the animation.
When you call start() the animation begins. During the whole animation,
the ValueAnimator calculates an elapsed fraction between 0 and 1, based on the duration of
the animation and how much time has elapsed. The elapsed fraction represents the percentage
of time that the animation has completed, 0 meaning 0% and 1 meaning 100%. For example,
in Figure 17.1, the elapsed fraction at t = 10 ms would be .25 because the total duration is t =
40 ms.
When the ValueAnimator is done calculating an elapsed fraction, it calls
the TimeInterpolator that is currently set, to calculate an interpolated fraction. An
interpolated fraction maps the elapsed fraction to a new fraction that takes into account the
time interpolation that is set. For example, in Figure 17.2, because the animation slowly
accelerates, the interpolated fraction, about .15, is less than the elapsed fraction, .25, at t = 10
ms. In Figure 17.1, the interpolated fraction is always the same as the elapsed fraction.
When the interpolated fraction is calculated, ValueAnimator calls the
appropriate TypeEvaluator, to calculate the value of the property that you are animating,
based on the interpolated fraction, the starting value, and the ending value of the animation.
For example, in Figure 17.2, the interpolated fraction was .15 at t = 10 ms, so the value for
the property at that time would be .15 X (40 - 0), or 6.
The com.example.android.apis.animation package in the API Demos sample
project provides many examples on how to use the property animation system.
Summary
In this unit we have discussed that Animation in Android which is supported with
Property Animation, View Animation and Drawable Animation. A property animation
changes a property's value over a specified length of time. To animate something, you specify
the object property that you want to animate, such as an object's position on the screen, how
long you want to animate it for, and what values you want to animate between them.

Weitere ähnliche Inhalte

Ă„hnlich wie Android animation in android-chapter17

Android App Development - 12 animations
Android App Development - 12 animationsAndroid App Development - 12 animations
Android App Development - 12 animationsDiego Grancini
 
Seven Peaks Speaks - Android Jetpack Compose Animation
Seven Peaks Speaks - Android Jetpack Compose AnimationSeven Peaks Speaks - Android Jetpack Compose Animation
Seven Peaks Speaks - Android Jetpack Compose AnimationSeven Peaks Speaks
 
Android Training (Animation)
Android Training (Animation)Android Training (Animation)
Android Training (Animation)Khaled Anaqwa
 
Animation in android
Animation in androidAnimation in android
Animation in androidJatin_123
 
How to Animate a Widget Across Screens in Flutter.pptx
How to Animate a Widget Across Screens in Flutter.pptxHow to Animate a Widget Across Screens in Flutter.pptx
How to Animate a Widget Across Screens in Flutter.pptxFlutter Agency
 
Trends in Computer Graphics
Trends in Computer GraphicsTrends in Computer Graphics
Trends in Computer GraphicsSajal Maharjan
 
Animation
AnimationAnimation
AnimationVasu Mathi
 
Unity3d scripting tutorial
Unity3d scripting tutorialUnity3d scripting tutorial
Unity3d scripting tutorialhungnttg
 
Programming scripting
Programming scriptingProgramming scripting
Programming scriptingHatta Awang
 
Animation
AnimationAnimation
AnimationVasu Mathi
 
Animation
AnimationAnimation
AnimationVasu Mathi
 
IRJET- 3D Vision System using Calibrated Stereo Camera
IRJET- 3D Vision System using Calibrated Stereo CameraIRJET- 3D Vision System using Calibrated Stereo Camera
IRJET- 3D Vision System using Calibrated Stereo CameraIRJET Journal
 
How to Create Animation Using the AnimatedAlign Widget.pptx
How to Create Animation Using the AnimatedAlign Widget.pptxHow to Create Animation Using the AnimatedAlign Widget.pptx
How to Create Animation Using the AnimatedAlign Widget.pptxFlutter Agency
 
Animation
AnimationAnimation
AnimationFae Kaal
 
Multimedia chapter 5
Multimedia chapter 5Multimedia chapter 5
Multimedia chapter 5PrathimaBaliga
 
Computer animation Computer Graphics
Computer animation Computer Graphics Computer animation Computer Graphics
Computer animation Computer Graphics University of Potsdam
 

Ă„hnlich wie Android animation in android-chapter17 (20)

Android App Development - 12 animations
Android App Development - 12 animationsAndroid App Development - 12 animations
Android App Development - 12 animations
 
Seven Peaks Speaks - Android Jetpack Compose Animation
Seven Peaks Speaks - Android Jetpack Compose AnimationSeven Peaks Speaks - Android Jetpack Compose Animation
Seven Peaks Speaks - Android Jetpack Compose Animation
 
Android Training (Animation)
Android Training (Animation)Android Training (Animation)
Android Training (Animation)
 
Animation in android
Animation in androidAnimation in android
Animation in android
 
Android animation theory
Android animation theoryAndroid animation theory
Android animation theory
 
How to Animate a Widget Across Screens in Flutter.pptx
How to Animate a Widget Across Screens in Flutter.pptxHow to Animate a Widget Across Screens in Flutter.pptx
How to Animate a Widget Across Screens in Flutter.pptx
 
Trends in Computer Graphics
Trends in Computer GraphicsTrends in Computer Graphics
Trends in Computer Graphics
 
Animation
AnimationAnimation
Animation
 
Unity3d scripting tutorial
Unity3d scripting tutorialUnity3d scripting tutorial
Unity3d scripting tutorial
 
Programming scripting
Programming scriptingProgramming scripting
Programming scripting
 
Animation
AnimationAnimation
Animation
 
Android view animation in android-chapter18
Android view animation in android-chapter18Android view animation in android-chapter18
Android view animation in android-chapter18
 
Ch07
Ch07Ch07
Ch07
 
Animation
AnimationAnimation
Animation
 
IRJET- 3D Vision System using Calibrated Stereo Camera
IRJET- 3D Vision System using Calibrated Stereo CameraIRJET- 3D Vision System using Calibrated Stereo Camera
IRJET- 3D Vision System using Calibrated Stereo Camera
 
How to Create Animation Using the AnimatedAlign Widget.pptx
How to Create Animation Using the AnimatedAlign Widget.pptxHow to Create Animation Using the AnimatedAlign Widget.pptx
How to Create Animation Using the AnimatedAlign Widget.pptx
 
Animation
AnimationAnimation
Animation
 
Animation
AnimationAnimation
Animation
 
Multimedia chapter 5
Multimedia chapter 5Multimedia chapter 5
Multimedia chapter 5
 
Computer animation Computer Graphics
Computer animation Computer Graphics Computer animation Computer Graphics
Computer animation Computer Graphics
 

Mehr von Dr. Ramkumar Lakshminarayanan

Creating Image Gallery - Android app (in tamil)
Creating Image Gallery - Android app (in tamil)Creating Image Gallery - Android app (in tamil)
Creating Image Gallery - Android app (in tamil)Dr. Ramkumar Lakshminarayanan
 

Mehr von Dr. Ramkumar Lakshminarayanan (20)

IT security awareness
IT security awarenessIT security awareness
IT security awareness
 
Basics of IT security
Basics of IT securityBasics of IT security
Basics of IT security
 
IT Security Awareness Posters
IT Security Awareness PostersIT Security Awareness Posters
IT Security Awareness Posters
 
Normalisation revision
Normalisation revisionNormalisation revision
Normalisation revision
 
Windows mobile programming
Windows mobile programmingWindows mobile programming
Windows mobile programming
 
Concurrency control
Concurrency controlConcurrency control
Concurrency control
 
Web technology today
Web technology todayWeb technology today
Web technology today
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Phonegap for Android
Phonegap for AndroidPhonegap for Android
Phonegap for Android
 
Create and Sell Android App (in tamil)
Create and Sell Android App (in tamil)Create and Sell Android App (in tamil)
Create and Sell Android App (in tamil)
 
Android app - Creating Live Wallpaper (tamil)
Android app - Creating Live Wallpaper (tamil)Android app - Creating Live Wallpaper (tamil)
Android app - Creating Live Wallpaper (tamil)
 
Android Tips (Tamil)
Android Tips (Tamil)Android Tips (Tamil)
Android Tips (Tamil)
 
Android Animation (in tamil)
Android Animation (in tamil)Android Animation (in tamil)
Android Animation (in tamil)
 
Creating List in Android App (in tamil)
Creating List in Android App (in tamil)Creating List in Android App (in tamil)
Creating List in Android App (in tamil)
 
Single Touch event view in Android (in tamil)
Single Touch event view in Android (in tamil)Single Touch event view in Android (in tamil)
Single Touch event view in Android (in tamil)
 
Android Application using seekbar (in tamil)
Android Application using seekbar (in tamil)Android Application using seekbar (in tamil)
Android Application using seekbar (in tamil)
 
Rating Bar in Android Example
Rating Bar in Android ExampleRating Bar in Android Example
Rating Bar in Android Example
 
Creating Image Gallery - Android app (in tamil)
Creating Image Gallery - Android app (in tamil)Creating Image Gallery - Android app (in tamil)
Creating Image Gallery - Android app (in tamil)
 
Create Android App using web view (in tamil)
Create Android App using web view (in tamil)Create Android App using web view (in tamil)
Create Android App using web view (in tamil)
 
Hardware Interface in Android (in tamil)
Hardware Interface in Android (in tamil)Hardware Interface in Android (in tamil)
Hardware Interface in Android (in tamil)
 

KĂĽrzlich hochgeladen

CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceanilsa9823
 
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceDelhi Call girls
 
Call US Pooja 9892124323 âś“Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 âś“Call Girls In Mira Road ( Mumbai ) secure service,Call US Pooja 9892124323 âś“Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 âś“Call Girls In Mira Road ( Mumbai ) secure service,Pooja Nehwal
 
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPowerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPsychicRuben LoveSpells
 
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceanilsa9823
 
9892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x79892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x7Pooja Nehwal
 
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRFULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRnishacall1
 

KĂĽrzlich hochgeladen (7)

CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
 
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
 
Call US Pooja 9892124323 âś“Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 âś“Call Girls In Mira Road ( Mumbai ) secure service,Call US Pooja 9892124323 âś“Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 âś“Call Girls In Mira Road ( Mumbai ) secure service,
 
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPowerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
 
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
 
9892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x79892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x7
 
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRFULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
 

Android animation in android-chapter17

  • 1. Chapter 17 Animation in Android By Dr. Ramkumar Lakshminarayanan Introduction Android provides a variety of powerful APIs for applying animation to UI elements and drawing custom 2D and 3D graphics. This unit provide an overview of the APIs and system capabilities available and help you decide with approach is best. Animation The Android framework provides two animation systems: property animation (introduced in Android 3.0) and view animation. Both animation systems are viable options, but the property animation system, in general, is the preferred method to use, because it is more flexible and offers more features. In addition to these two systems, you can utilize Drawable animation, which allows you to load drawable resources and display them one frame after another. Property Animation Introduced in Android 3.0 (API level 11), the property animation system lets you animate properties of any object, including ones that are not rendered to the screen. The system is extensible and lets you animate properties of custom types as well. View Animation View Animation is the older system and can only be used for Views. It is relatively easy to setup and offers enough capabilities to meet many application's needs. Drawable Animation Drawable animation involves displaying Drawable resources one after another, like a roll of film. This method of animation is useful if you want to animate things that are easier to represent with Drawable resources, such as a progression of bitmaps. 2D and 3D Graphics When writing an application, it's important to consider exactly what your graphical demands will be. Varying graphical tasks are best accomplished with varying techniques. For example, graphics and animations for a rather static application should be implemented much differently than graphics and animations for an interactive game. Here, we'll discuss a few of the options you have for drawing graphics on Android and which tasks they're best suited for. Canvas and Drawables
  • 2. Android provides a set of View widgets that provide general functionality for a wide array of user interfaces. You can also extend these widgets to modify the way they look or behave. In addition, you can do your own custom 2D rendering using the various drawing methods contained in the Canvas class or create Drawable objects for things such as textured buttons or frame-by-frame animations. Hardware Acceleration Beginning in Android 3.0, you can hardware accelerate the majority of the drawing done by the Canvas APIs to further increase their performance. OpenGL Android supports OpenGL ES 1.0 and 2.0, with Android framework APIs as well as natively with the Native Development Kit (NDK). Using the framework APIs is desireable when you want to add a few graphical enhancements to your application that are not supported with the Canvas APIs, or if you desire platform independence and don't demand high performance. There is a performance hit in using the framework APIs compared to the NDK, so for many graphic intensive applications such as games, using the NDK is beneficial. OpenGL with the NDK is also useful if you have a lot of native code that you want to port over to Android. Property Animation The property animation system is a robust framework that allows you to animate almost anything. You can define an animation to change any object property over time, regardless of whether it draws to the screen or not. A property animation changes a property's (a field in an object) value over a specified length of time. To animate something, you specify the object property that you want to animate, such as an object's position on the screen, how long you want to animate it for, and what values you want to animate between. The property animation system lets you define the following characteristics of an animation: ď‚· Duration: You can specify the duration of an animation. The default length is 300 ms. ď‚· Time interpolation: You can specify how the values for the property are calculated as a function of the animation's current elapsed time. ď‚· Repeat count and behavior: You can specify whether or not to have an animation repeat when it reaches the end of a duration and how many times to repeat the animation. You can also specify whether you want the animation to play back in reverse. Setting it to reverse plays the animation forwards then backwards repeatedly, until the number of repeats is reached. ď‚· Animator sets: You can group animations into logical sets that play together or sequentially or after specified delays.
  • 3. ď‚· Frame refresh delay: You can specify how often to refresh frames of your animation. The default is set to refresh every 10 ms, but the speed in which your application can refresh frames is ultimately dependent on how busy the system is overall and how fast the system can service the underlying timer. First, let's go over how an animation works with a simple example. Figure 17.1 depicts a hypothetical object that is animated with its x property, which represents its horizontal location on a screen. The duration of the animation is set to 40 ms and the distance to travel is 40 pixels. Every 10 ms, which is the default frame refresh rate, the object moves horizontally by 10 pixels. At the end of 40ms, the animation stops, and the object ends at horizontal position 40. This is an example of an animation with linear interpolation, meaning the object moves at a constant speed. Figure 17.1 Linear Animation You can also specify animations to have a non-linear interpolation. Figure 17.2 illustrates a hypothetical object that accelerates at the beginning of the animation, and decelerates at the end of the animation. The object still moves 40 pixels in 40 ms, but non- linearly. In the beginning, this animation accelerates up to the halfway point then decelerates from the halfway point until the end of the animation. As Figure 17.2 shows, the distance traveled at the beginning and end of the animation is less than in the middle. Figure 17.2 Non-linear Animation Let's take a detailed look at how the important components of the property animation system would calculate animations like the ones illustrated above. Figure 17.3 depicts how the main classes work with one another.
  • 4. Figure 17.3 Animation Calculation The ValueAnimator object keeps track of your animation's timing, such as how long the animation has been running, and the current value of the property that it is animating. The ValueAnimator encapsulates a TimeInterpolator, which defines animation interpolation, and a TypeEvaluator, which defines how to calculate values for the property being animated. For example, in Figure 17.2, the TimeInterpolator used would be AccelerateDecelerateInterpolator and the TypeEvaluator would be IntEvaluator. To start an animation, create a ValueAnimator and give it the starting and ending values for the property that you want to animate, along with the duration of the animation. When you call start() the animation begins. During the whole animation, the ValueAnimator calculates an elapsed fraction between 0 and 1, based on the duration of the animation and how much time has elapsed. The elapsed fraction represents the percentage of time that the animation has completed, 0 meaning 0% and 1 meaning 100%. For example, in Figure 17.1, the elapsed fraction at t = 10 ms would be .25 because the total duration is t = 40 ms. When the ValueAnimator is done calculating an elapsed fraction, it calls the TimeInterpolator that is currently set, to calculate an interpolated fraction. An interpolated fraction maps the elapsed fraction to a new fraction that takes into account the time interpolation that is set. For example, in Figure 17.2, because the animation slowly accelerates, the interpolated fraction, about .15, is less than the elapsed fraction, .25, at t = 10 ms. In Figure 17.1, the interpolated fraction is always the same as the elapsed fraction. When the interpolated fraction is calculated, ValueAnimator calls the appropriate TypeEvaluator, to calculate the value of the property that you are animating, based on the interpolated fraction, the starting value, and the ending value of the animation. For example, in Figure 17.2, the interpolated fraction was .15 at t = 10 ms, so the value for the property at that time would be .15 X (40 - 0), or 6. The com.example.android.apis.animation package in the API Demos sample project provides many examples on how to use the property animation system. Summary In this unit we have discussed that Animation in Android which is supported with Property Animation, View Animation and Drawable Animation. A property animation
  • 5. changes a property's value over a specified length of time. To animate something, you specify the object property that you want to animate, such as an object's position on the screen, how long you want to animate it for, and what values you want to animate between them.