14b3e912102d92c3555aae362da67178dcf5bcc55Robert Lypage.title=Property Animation
233baa5ad7d8cdcc89ce4fbc3bc8cd537d5f5d639Joe Fernandezpage.tags=valueanimator,objectanimator,layouttransition,ViewPropertyAnimator
34b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly@jd:body
44b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
54b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <div id="qv-wrapper">
64b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <div id="qv">
74b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <h2>In this document</h2>
84b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
94b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <ol>
104b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <li><a href="#how">How Property Animation Works</a></li>
114b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
124b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <li><a href="#value-animator">Animating with ValueAnimator</a></li>
134b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
144b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <li><a href="#object-animator">Animating with ObjectAnimator</a></li>
154b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
164b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <li><a href="#choreography">Choreographing Multiple Animations with
174b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        AnimatorSet</a></li>
184b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
194b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <li><a href="#listeners">Animation Listeners</a></li>
204b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
214b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <li><a href="#type-evaluator">Using a TypeEvaluator</a></li>
224b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
234b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <li><a href="#interpolators">Using Interpolators</a></li>
244b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
254b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <li><a href="#keyframes">Specifying Keyframes</a></li>
264b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
274b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <li><a href="#layout">Animating Layout Changes to ViewGroups</a></li>
284b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
294b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <li><a href="#views">Animating Views</a>
304b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <ol>
314b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly            <li><a href="#view-prop-animator">ViewPropertyAnimator</a></li>
324b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          </ol>
334b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        </li>
344b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
354b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <li><a href="#declaring-xml">Declaring Animations in XML</a></li>
364b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      </ol>
374b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
384b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <h2>Key classes</h2>
394b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
404b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <ol>
414b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <li><code><a href=
424b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        "/reference/android/animation/ValueAnimator.html">ValueAnimator</a></code></li>
434b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
444b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <li><code><a href=
454b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        "/reference/android/animation/ObjectAnimator.html">ObjectAnimator</a></code></li>
464b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
474b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <li><code><a href=
484b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        "/reference/android/animation/TypeEvaluator.html">TypeEvaluator</a></code></li>
494b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      </ol>
504b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
514b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <h2>Related samples</h2>
524b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
534b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <ol>
544b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <li><a href=
554b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        "{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/animation/index.html">API
564b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        Demos</a></li>
574b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      </ol>
584b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    </div>
594b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  </div>
604b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>The property animation system is a robust framework that allows you
614b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  to animate almost anything. You can define an animation to change any object property over time,
624b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  regardless of whether it draws to the screen or not. A property animation changes a property's
634b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  (a field in an object) value over a specified length of time. To animate something, you specify the
644b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  object property that you want to animate, such as an object's position on the screen, how long
654b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  you want to animate it for, and what values you want to animate between. </p>
664b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
674b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>The property animation system lets you define the following characteristics of an
684b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  animation:</p>
694b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
704b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <ul>
714b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <li>Duration: You can specify the duration of an animation. The default length is 300 ms.</li>
724b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
734b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <li>Time interpolation: You can specify how the values for the property are calculated as a
744b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    function of the animation's current elapsed time.</li>
754b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
764b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <li>Repeat count and behavior: You can specify whether or not to have an animation repeat when
774b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    it reaches the end of a duration and how many times to repeat the animation. You can also
784b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    specify whether you want the animation to play back in reverse. Setting it to reverse plays
794b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    the animation forwards then backwards repeatedly, until the number of repeats is reached.</li>
804b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
814b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <li>Animator sets: You can group animations into logical sets that play together or
824b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    sequentially or after specified delays.</li>
834b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
844b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <li>Frame refresh delay: You can specify how often to refresh frames of your animation. The
854b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    default is set to  refresh every 10 ms, but the speed in which your application can refresh frames is
864b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    ultimately dependent on how busy the system is overall and how fast the system can service the underlying timer.</li>
874b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  </ul>
884b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
894b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
904b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <h2 id="how">How Property Animation Works</h2>
914b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
924b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>First, let's go over how an animation works with a simple example. Figure 1 depicts a
934b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  hypothetical object that is animated with its <code>x</code> property, which represents its
944b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  horizontal location on a screen. The duration of the animation is set to 40 ms and the distance
954b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  to travel is 40 pixels. Every 10 ms, which is the default frame refresh rate, the object moves
964b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  horizontally by 10 pixels. At the end of 40ms, the animation stops, and the object ends at
974b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  horizontal position 40. This is an example of an animation with linear interpolation, meaning the
984b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  object moves at a constant speed.</p><img src="{@docRoot}images/animation/animation-linear.png">
994b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
1004b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p class="img-caption"><strong>Figure 1.</strong> Example of a linear animation</p>
1014b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
1024b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>You can also specify animations to have a non-linear interpolation. Figure 2 illustrates a
1034b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  hypothetical object that accelerates at the beginning of the animation, and decelerates at the
1044b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  end of the animation. The object still moves 40 pixels in 40 ms, but non-linearly. In the
1054b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  beginning, this animation accelerates up to the halfway point then decelerates from the
1064b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  halfway point until the end of the animation. As Figure 2 shows, the distance traveled
1074b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  at the beginning and end of the animation is less than in the middle.</p><img src=
1084b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  "{@docRoot}images/animation/animation-nonlinear.png">
1094b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
1104b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p class="img-caption"><strong>Figure 2.</strong> Example of a non-linear animation</p>
1114b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
1124b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>Let's take a detailed look at how the important components of the property animation system
1134b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  would calculate animations like the ones illustrated above. Figure 3 depicts how the main classes
1144b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  work with one another.</p><img src="{@docRoot}images/animation/valueanimator.png">
1154b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
1164b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p class="img-caption"><strong>Figure 3.</strong> How animations are calculated</p>
1174b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
1184b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>The {@link android.animation.ValueAnimator} object keeps track of your animation's timing,
1194b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  such as how long the animation has been running, and the current value of the property that it is
1204b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  animating.</p>
1214b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
1224b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>The {@link android.animation.ValueAnimator} encapsulates a {@link
1234b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.animation.TimeInterpolator}, which defines animation interpolation, and a {@link
1244b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.animation.TypeEvaluator}, which defines how to calculate values for the property being
1254b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  animated. For example, in Figure 2, the {@link android.animation.TimeInterpolator} used would be
1264b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  {@link android.view.animation.AccelerateDecelerateInterpolator} and the {@link
1274b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.animation.TypeEvaluator} would be {@link android.animation.IntEvaluator}.</p>
1284b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
1294b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>To start an animation, create a {@link android.animation.ValueAnimator} and give it the
1304b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  starting and ending values for the property that you want to animate, along with the duration of
1314b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  the animation. When you call {@link android.animation.ValueAnimator#start start()} the animation
1324b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  begins. During the whole animation, the {@link android.animation.ValueAnimator} calculates an <em>elapsed fraction</em>
1334b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  between 0 and 1, based on the duration of the animation and how much time has elapsed. The
1344b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  elapsed fraction represents the percentage of time that the animation has completed, 0 meaning 0%
1354b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  and 1 meaning 100%. For example, in Figure 1, the elapsed fraction at t = 10 ms would be .25
1364b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  because the total duration is t = 40 ms.</p>
1374b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
1384b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>When the {@link android.animation.ValueAnimator} is done calculating an elapsed fraction, it
1394b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  calls the {@link android.animation.TimeInterpolator} that is currently set, to calculate an
1404b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <em>interpolated fraction</em>. An interpolated fraction maps the elapsed fraction to a new
1414b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  fraction that takes into account the time interpolation that is set. For example, in Figure 2,
1424b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  because the animation slowly accelerates, the interpolated fraction, about .15, is less than the
1434b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  elapsed fraction, .25, at t = 10 ms. In Figure 1, the interpolated fraction is always the same as
1444b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  the elapsed fraction.</p>
1454b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
1464b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>When the interpolated fraction is calculated, {@link android.animation.ValueAnimator} calls
1474b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  the appropriate {@link android.animation.TypeEvaluator}, to calculate the value of the
1484b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  property that you are animating, based on the interpolated fraction, the starting value, and the
1494b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  ending value of the animation. For example, in Figure 2, the interpolated fraction was .15 at t =
1504b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  10 ms, so the value for the property at that time would be .15 X (40 - 0), or 6.</p>
1514b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
1524b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly <!-- <p>When the final value is calculated, the {@link android.animation.ValueAnimator} calls the
1534b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  {@link android.animation.ValueAnimator.AnimatorUpdateListener#onAnimationUpdate
1544b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  onAnimationUpdate()} method. Implement this callback to obtain the property value by
1554b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  calling {@link android.animation.ValueAnimator#getAnimatedValue getAnimatedValue()} and set the
1564b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  value for the property in the object that you are animating. Setting the property doesn't redraw
1574b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  the object on the screen, so you need to call {@link
1584b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.view.View#invalidate invalidate()} to refresh the View that the object
1594b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  resides in. If the object is actually a View object, then the system calls {@link
1604b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.view.View#invalidate invalidate()} when the property is changed.
1614b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  The system redraws the window and the {@link android.animation.ValueAnimator}
1624b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  repeats the process.</p>-->
1634b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
1644b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>The <code>com.example.android.apis.animation</code> package in the <a href=
1654b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  "{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/animation/index.html">API
1664b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  Demos</a> sample project provides many examples on how to use the property
1674b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  animation system.</p>
16850e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  
16950e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  <h2 id="property-vs-view">How Property Animation Differs from View Animation</h2>
17050e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  
17150e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  <p>The view animation system provides the capability to only animate {@link android.view.View}
17250e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  objects, so if you wanted to animate non-{@link android.view.View} objects, you have to implement
17350e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  your own code to do so. The view animation system is also constrained in the fact that it only
17450e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  exposes a few aspects of a {@link android.view.View} object to animate, such as the scaling and
17550e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  rotation of a View but not the background color, for instance.</p>
17650e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main
17750e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  <p>Another disadvantage of the view animation system is that it only modified where the
17850e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  View was drawn, and not the actual View itself. For instance, if you animated a button to move
17950e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  across the screen, the button draws correctly, but the actual location where you can click the
18050e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  button does not change, so you have to implement your own logic to handle this.</p>
18150e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main
18250e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  <p>With the property animation system, these constraints are completely removed, and you can animate
18350e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  any property of any object (Views and non-Views) and the object itself is actually modified.
18450e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  The property animation system is also more robust in the way it carries out animation. At
18550e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  a high level, you assign animators to the properties that you want to animate, such as color,
18650e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  position, or size and can define aspects of the animation such as interpolation and
18750e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  synchronization of multiple animators.</p>
18850e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main
18950e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  <p>The view animation system, however, takes less time to setup and requires less code to write.
19050e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  If view animation accomplishes everything that you need to do, or if your existing code already
19150e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  works the way you want, there is no need to use the property animation system. It also might
19250e990c64fa23ce94efa76b9e72df7f8ec3cee6aScott Main  make sense to use both animation systems for different situations if the use case arises.</p>
1934b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
1944b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <h2>API Overview</h2>
1954b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
1964b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>You can find most of the property animation system's APIs in {@link android.animation
1974b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.animation}. Because the view animation system already
1984b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  defines many interpolators in {@link android.view.animation android.view.animation}, you can use
1994b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  those interpolators in the property animation system as well. The following tables describe the main
2004b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  components of the property animation system.</p>
2014b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
2024b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>The {@link android.animation.Animator} class provides the basic structure for creating
2034b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  animations. You normally do not use this class directly as it only provides minimal
2044b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  functionality that must be extended to fully support animating values. The following
2054b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  subclasses extend {@link android.animation.Animator}:
2064b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  </p>
2074b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p class="table-caption"><strong>Table 1.</strong> Animators</p>
2084b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <table>
2094b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <tr>
2104b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <th>Class</th>
2114b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
2124b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <th>Description</th>
2134b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        </tr>
2144b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
2154b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <tr>
2164b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>{@link android.animation.ValueAnimator}</td>
2174b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
2184b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>The main timing engine for property animation that also computes the values for the
2194b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          property to be animated. It has all of the core functionality that calculates animation
2204b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          values and contains the timing details of each animation, information about whether an
2214b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          animation repeats, listeners that receive update events, and the ability to set custom
2224b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          types to evaluate. There are two pieces to animating properties: calculating the animated
2234b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          values and setting those values on the object and property that is being animated. {@link
2244b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          android.animation.ValueAnimator} does not carry out the second piece, so you must listen
2254b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          for updates to values calculated by the {@link android.animation.ValueAnimator} and
2264b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          modify the objects that you want to animate with your own logic. See the section about
2274b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <a href="#value-animator">Animating with ValueAnimator</a> for more information.</td>
2284b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        </tr>
2294b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
2304b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <tr>
2314b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>{@link android.animation.ObjectAnimator}</td>
2324b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
2334b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>A subclass of {@link android.animation.ValueAnimator} that allows you to set a target
2344b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          object and object property to animate. This class updates the property accordingly when
2354b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          it computes a new value for the animation. You want to use
2364b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          {@link android.animation.ObjectAnimator} most of the time,
2374b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          because it makes the process of animating values on target objects much easier. However,
2384b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          you sometimes want to use {@link android.animation.ValueAnimator} directly because {@link
2394b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          android.animation.ObjectAnimator} has a few more restrictions, such as requiring specific
2404b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          acessor methods to be present on the target object.</td>
2414b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        </tr>
2424b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
2434b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <tr>
2444b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>{@link android.animation.AnimatorSet}</td>
2454b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
2464b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>Provides a mechanism to group animations together so that they run in
2474b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          relation to one another. You can set animations to play together, sequentially, or after
2484b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          a specified delay. See the section about <a href="#choreography">Choreographing multiple
2494b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          animations with Animator Sets</a> for more information.</td>
2504b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        </tr>
2514b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      </table>
2524b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
2534b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
2544b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <p>Evaluators tell the property animation system how to calculate values for a given
2554b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      property. They take the timing data that is provided by an {@link android.animation.Animator}
2564b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      class, the animation's start and end value, and calculate the animated values of the property
2574b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      based on this data. The property animation system provides the following evaluators:</p>
2584b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <p class="table-caption"><strong>Table 2.</strong> Evaluators</p>
2594b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <table>
2604b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <tr>
2614b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <th>Class/Interface</th>
2624b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
2634b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <th>Description</th>
2644b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        </tr>
2654b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
2664b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <tr>
2674b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>{@link android.animation.IntEvaluator}</td>
2684b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
2694b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>The default evaluator to calculate values for <code>int</code> properties.</td>
2704b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        </tr>
2714b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
2724b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <tr>
2734b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>{@link android.animation.FloatEvaluator}</td>
2744b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
2754b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>The default evaluator to calculate values for <code>float</code> properties.</td>
2764b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        </tr>
2774b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
2784b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <tr>
2794b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>{@link android.animation.ArgbEvaluator}</td>
2804b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
2814b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>The default evaluator to calculate values for color properties that are represented
2824b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          as hexidecimal values.</td>
2834b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        </tr>
2844b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
2854b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <tr>
2864b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>{@link android.animation.TypeEvaluator}</td>
2874b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
2884b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>An interface that allows you to create your own evaluator. If you are animating an
2894b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          object property that is <em>not</em> an <code>int</code>, <code>float</code>, or color,
2904b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          you must implement the {@link android.animation.TypeEvaluator} interface to specify how
2914b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          to compute the object property's animated values. You can also specify a custom {@link
2924b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          android.animation.TypeEvaluator} for <code>int</code>, <code>float</code>, and color
2934b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          values as well, if you want to process those types differently than the default behavior.
2944b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          See the section about <a href="#type-evaluator">Using a TypeEvaluator</a> for more
2954b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          information on how to write a custom evaluator.</td>
2964b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        </tr>
2974b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      </table>
2984b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
2994b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
3004b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
3014b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
3024b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <p>A time interpolator defines how specific values in an animation are calculated as a
3034b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      function of time. For example, you can specify animations to happen linearly across the whole
3044b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      animation, meaning the animation moves evenly the entire time, or you can specify animations
3054b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      to use non-linear time, for example, accelerating at the beginning and decelerating at the
3064b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      end of the animation. Table 3 describes the interpolators that are contained in {@link
3074b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      android.view.animation android.view.animation}. If none of the provided interpolators suits
3084b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      your needs, implement the {@link android.animation.TimeInterpolator} interface and create your own. See <a href=
3094b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  "#interpolators">Using interpolators</a> for more information on how to write a custom
3104b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  interpolator.</p>
3114b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <p class="table-caption"><strong>Table 3.</strong> Interpolators</p>
3124b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <table>
3134b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <tr>
3144b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <th>Class/Interface</th>
3154b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
3164b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <th>Description</th>
3174b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        </tr>
3184b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
3194b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <tr>
3204b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>{@link android.view.animation.AccelerateDecelerateInterpolator}</td>
3214b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
3224b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>An interpolator whose rate of change starts and ends slowly but accelerates
3234b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          through the middle.</td>
3244b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        </tr>
3254b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
3264b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <tr>
3274b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>{@link android.view.animation.AccelerateInterpolator}</td>
3284b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
3294b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>An interpolator whose rate of change starts out slowly and then
3304b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          accelerates.</td>
3314b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        </tr>
3324b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
3334b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <tr>
3344b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>{@link android.view.animation.AnticipateInterpolator}</td>
3354b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
3364b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>An interpolator whose change starts backward then flings forward.</td>
3374b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        </tr>
3384b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
3394b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <tr>
3404b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>{@link android.view.animation.AnticipateOvershootInterpolator}</td>
3414b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
3424b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>An interpolator whose change starts backward, flings forward and overshoots
3434b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          the target value, then finally goes back to the final value.</td>
3444b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        </tr>
3454b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
3464b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <tr>
3474b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>{@link android.view.animation.BounceInterpolator}</td>
3484b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
3494b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>An interpolator whose change bounces at the end.</td>
3504b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        </tr>
3514b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
3524b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <tr>
3534b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>{@link android.view.animation.CycleInterpolator}</td>
3544b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
3554b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>An interpolator whose animation repeats for a specified number of cycles.</td>
3564b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        </tr>
3574b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
3584b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <tr>
3594b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>{@link android.view.animation.DecelerateInterpolator}</td>
3604b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
3614b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>An interpolator whose rate of change starts out quickly and and then
3624b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          decelerates.</td>
3634b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        </tr>
3644b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
3654b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <tr>
3664b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>{@link android.view.animation.LinearInterpolator}</td>
3674b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
3684b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>An interpolator whose rate of change is constant.</td>
3694b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        </tr>
3704b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
3714b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <tr>
3724b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>{@link android.view.animation.OvershootInterpolator}</td>
3734b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
3744b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>An interpolator whose change flings forward and overshoots the last value then
3754b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          comes back.</td>
3764b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        </tr>
3774b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
3784b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <tr>
3794b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>{@link android.animation.TimeInterpolator}</td>
3804b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
3814b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <td>An interface that allows you to implement your own interpolator.</td>
3824b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        </tr>
3834b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      </table>
3844b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
3854b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <h2 id="value-animator">Animating with ValueAnimator</h2>
3864b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
3874b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>The {@link android.animation.ValueAnimator} class lets you animate values of some type for the
3884b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  duration of an animation by specifying a set of <code>int</code>, <code>float</code>, or color
3894b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  values to animate through. You obtain a {@link android.animation.ValueAnimator} by calling one of
3904b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  its factory methods: {@link android.animation.ValueAnimator#ofInt ofInt()}, {@link
3914b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.animation.ValueAnimator#ofFloat ofFloat()}, or {@link
3924b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.animation.ValueAnimator#ofObject ofObject()}. For example:</p>
3934b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <pre>
3944b3e912102d92c3555aae362da67178dcf5bcc55Robert LyValueAnimator animation = ValueAnimator.ofFloat(0f, 1f);
3954b3e912102d92c3555aae362da67178dcf5bcc55Robert Lyanimation.setDuration(1000);
3964b3e912102d92c3555aae362da67178dcf5bcc55Robert Lyanimation.start();
3974b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly</pre>
3984b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
3994b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>In this code, the {@link android.animation.ValueAnimator} starts calculating the values of the
4004b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  animation, between 0 and 1, for a duration of 1000 ms, when the <code>start()</code> method
4014b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  runs.</p>
4024b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
4034b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>You can also specify a custom type to animate by doing the following:</p>
4044b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <pre>
4054b3e912102d92c3555aae362da67178dcf5bcc55Robert LyValueAnimator animation = ValueAnimator.ofObject(new MyTypeEvaluator(), startPropertyValue, endPropertyValue);
4064b3e912102d92c3555aae362da67178dcf5bcc55Robert Lyanimation.setDuration(1000);
4074b3e912102d92c3555aae362da67178dcf5bcc55Robert Lyanimation.start();
4084b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly</pre>
4094b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
4104b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>In this code, the {@link android.animation.ValueAnimator} starts calculating the values of the
4114b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  animation, between <code>startPropertyValue</code> and <code>endPropertyValue</code> using the
4124b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  logic supplied by <code>MyTypeEvaluator</code> for a duration of 1000 ms, when the {@link
4134b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.animation.ValueAnimator#start start()} method runs.</p>
4144b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
4154b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>The previous code snippets, however, has no real effect on an object, because the {@link
4164b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.animation.ValueAnimator} does not operate on objects or properties directly. The most likely thing
4174b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  that you want to do is modify the objects that you want to animate with these calculated values. You do
4184b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  this by defining listeners in the {@link android.animation.ValueAnimator} to appropriately handle important events
4194b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  during the animation's lifespan, such as frame updates. When implementing the listeners, you can
4204b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  obtain the calculated value for that specific frame refresh by calling {@link
4214b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.animation.ValueAnimator#getAnimatedValue getAnimatedValue()}. For more information on listeners,
4224b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  see the section about <a href="#listeners">Animation Listeners</a>.
4234b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
4244b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <h2 id="object-animator">Animating with ObjectAnimator</h2>
4254b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
4264b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>The {@link android.animation.ObjectAnimator} is a subclass of the {@link
4274b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.animation.ValueAnimator} (discussed in the previous section) and combines the timing
4284b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  engine and value computation of {@link android.animation.ValueAnimator} with the ability to
4294b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  animate a named property of a target object. This makes animating any object much easier, as you
4304b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  no longer need to implement the {@link android.animation.ValueAnimator.AnimatorUpdateListener},
4314b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  because the animated property updates automatically.</p>
4324b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
4334b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>Instantiating an {@link android.animation.ObjectAnimator} is similar to a {@link
4344b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.animation.ValueAnimator}, but you also specify the object and the name of that object's property (as
4354b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  a String) along with the values to animate between:</p>
4364b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <pre>
4374b3e912102d92c3555aae362da67178dcf5bcc55Robert LyObjectAnimator anim = ObjectAnimator.ofFloat(foo, "alpha", 0f, 1f);
4384b3e912102d92c3555aae362da67178dcf5bcc55Robert Lyanim.setDuration(1000);
4394b3e912102d92c3555aae362da67178dcf5bcc55Robert Lyanim.start();
4404b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly</pre>
4414b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
4424b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>To have the {@link android.animation.ObjectAnimator} update properties correctly, you must do
4434b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  the following:</p>
4444b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
4454b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <ul>
4464b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <li>The object property that you are animating must have a setter function (in camel case) in the form of
4474b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <code>set&lt;propertyName&gt;()</code>. Because the {@link android.animation.ObjectAnimator}
4484b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    automatically updates the property during animation, it must be able to access the property
4494b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    with this setter method. For example, if the property name is <code>foo</code>, you need to
4504b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    have a <code>setFoo()</code> method. If this setter method does not exist, you have three
4514b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    options:
4524b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
4534b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <ul>
4544b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <li>Add the setter method to the class if you have the rights to do so.</li>
4554b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
4564b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <li>Use a wrapper class that you have rights to change and have that wrapper receive the
4574b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        value with a valid setter method and forward it to the original object.</li>
4584b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
4594b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <li>Use {@link android.animation.ValueAnimator} instead.</li>
4604b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      </ul>
4614b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    </li>
4624b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
4634b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <li>If you specify only one value for the <code>values...</code> parameter in one of the {@link
4644b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    android.animation.ObjectAnimator} factory methods, it is assumed to be the ending value of the
4654b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    animation. Therefore, the object property that you are animating must have a getter function
4664b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    that is used to obtain the starting value of the animation. The getter function must be in the
4674b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    form of <code>get&lt;propertyName&gt;()</code>. For example, if the property name is
4684b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <code>foo</code>, you need to have a <code>getFoo()</code> method.</li>
4694b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
4704b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <li>The getter (if needed) and setter methods of the property that you are animating must
4714b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    operate on the same type as the starting and ending values that you specify to {@link
4724b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    android.animation.ObjectAnimator}. For example, you must have
4734b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <code>targetObject.setPropName(float)</code> and <code>targetObject.getPropName(float)</code>
4744b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    if you construct the following {@link android.animation.ObjectAnimator}:
4754b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <pre>
4764b3e912102d92c3555aae362da67178dcf5bcc55Robert LyObjectAnimator.ofFloat(targetObject, "propName", 1f)
4774b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly</pre>
4784b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    </li>
4794b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
4804b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <li>Depending on what property or object you are animating, you might need to call the {@link
4813b9f0aa058e95fa0c998f787a8f4f7225e9850c0kmccormick    android.view.View#invalidate invalidate()} method on a View to force the screen to redraw itself with the
4824b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    updated animated values. You do this in the
4834b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    {@link android.animation.ValueAnimator.AnimatorUpdateListener#onAnimationUpdate onAnimationUpdate()}
4844b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    callback. For example, animating the color property of a Drawable object only cause updates to the
4854b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    screen when that object redraws itself. All of the property setters on View, such as
4864b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    {@link android.view.View#setAlpha setAlpha()} and {@link android.view.View#setTranslationX setTranslationX()}
4874b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    invalidate the View properly, so you do not need to invalidate the View when calling these
4884b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    methods with new values. For more information on listeners, see the section about <a href="#listeners">Animation Listeners</a>.
4894b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    </li>
4904b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  </ul>
4914b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
4924b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <h2 id="choreography">Choreographing Multiple Animations with AnimatorSet</h2>
4934b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
4944b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>In many cases, you want to play an animation that depends on when another animation starts or
4954b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  finishes. The Android system lets you bundle animations together into an {@link
4964b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.animation.AnimatorSet}, so that you can specify whether to start animations
4974b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  simultaneously, sequentially, or after a specified delay. You can also nest {@link
4984b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.animation.AnimatorSet} objects within each other.</p>
4994b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
5004b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>The following sample code taken from the <a href=
5014b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  "{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/animation/BouncingBalls.html">Bouncing
5024b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  Balls</a> sample (modified for simplicity) plays the following {@link android.animation.Animator}
5034b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  objects in the following manner:</p>
5044b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
5054b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <ol>
5064b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <li>Plays <code>bounceAnim</code>.</li>
5074b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
5084b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <li>Plays <code>squashAnim1</code>, <code>squashAnim2</code>, <code>stretchAnim1</code>, and
5094b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <code>stretchAnim2</code> at the same time.</li>
5104b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
5114b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <li>Plays <code>bounceBackAnim</code>.</li>
5124b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
5134b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <li>Plays <code>fadeAnim</code>.</li>
5144b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  </ol>
5154b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <pre>
5164b3e912102d92c3555aae362da67178dcf5bcc55Robert LyAnimatorSet bouncer = new AnimatorSet();
5174b3e912102d92c3555aae362da67178dcf5bcc55Robert Lybouncer.play(bounceAnim).before(squashAnim1);
5184b3e912102d92c3555aae362da67178dcf5bcc55Robert Lybouncer.play(squashAnim1).with(squashAnim2);
5194b3e912102d92c3555aae362da67178dcf5bcc55Robert Lybouncer.play(squashAnim1).with(stretchAnim1);
5204b3e912102d92c3555aae362da67178dcf5bcc55Robert Lybouncer.play(squashAnim1).with(stretchAnim2);
5214b3e912102d92c3555aae362da67178dcf5bcc55Robert Lybouncer.play(bounceBackAnim).after(stretchAnim2);
5224b3e912102d92c3555aae362da67178dcf5bcc55Robert LyValueAnimator fadeAnim = ObjectAnimator.ofFloat(newBall, "alpha", 1f, 0f);
5234b3e912102d92c3555aae362da67178dcf5bcc55Robert LyfadeAnim.setDuration(250);
5244b3e912102d92c3555aae362da67178dcf5bcc55Robert LyAnimatorSet animatorSet = new AnimatorSet();
5254b3e912102d92c3555aae362da67178dcf5bcc55Robert LyanimatorSet.play(bouncer).before(fadeAnim);
5264b3e912102d92c3555aae362da67178dcf5bcc55Robert LyanimatorSet.start();
5274b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly</pre>
5284b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
5294b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>For a more complete example on how to use animator sets, see the <a href=
5304b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  "{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/animation/BouncingBalls.html">Bouncing
5314b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  Balls</a> sample in APIDemos.</p>
5324b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
5334b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly<h2 id="listeners">Animation Listeners</h2>
5344b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly<p>
5354b3e912102d92c3555aae362da67178dcf5bcc55Robert LyYou can listen for important events during an animation's duration with the listeners described below.
5364b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly</p>
5374b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
5384b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <ul>
5394b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <li>{@link android.animation.Animator.AnimatorListener}
5404b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
5414b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <ul>
5424b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <li>{@link android.animation.Animator.AnimatorListener#onAnimationStart onAnimationStart()}
5434b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        - Called when the animation starts.</li>
5444b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
5454b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <li>{@link android.animation.Animator.AnimatorListener#onAnimationEnd onAnimationEnd()} -
5464b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        Called when the animation ends.</li>
5474b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
5484b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <li>{@link android.animation.Animator.AnimatorListener#onAnimationRepeat
5494b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        onAnimationRepeat()} - Called when the animation repeats itself.</li>
5504b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
5514b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <li>{@link android.animation.Animator.AnimatorListener#onAnimationCancel
5524b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        onAnimationCancel()} - Called when the animation is canceled. A cancelled animation
5534b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        also calls {@link android.animation.Animator.AnimatorListener#onAnimationEnd onAnimationEnd()},
5544b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        regardless of how they were ended.</li>
5554b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      </ul>
5564b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    </li>
5574b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
5584b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <li>{@link android.animation.ValueAnimator.AnimatorUpdateListener}
5594b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
5604b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <ul>
5614b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        <li>
5624b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <p>{@link android.animation.ValueAnimator.AnimatorUpdateListener#onAnimationUpdate
5634b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          onAnimationUpdate()} - called on every frame of the animation. Listen to this event to
5644b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          use the calculated values generated by {@link android.animation.ValueAnimator} during an
5654b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          animation. To use the value, query the {@link android.animation.ValueAnimator} object
5664b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          passed into the event to get the current animated value with the {@link
5674b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          android.animation.ValueAnimator#getAnimatedValue getAnimatedValue()} method. Implementing this
5684b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          listener is required if you use {@link android.animation.ValueAnimator}. </p>
5694b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
5704b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          <p>
5714b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          Depending on what property or object you are animating, you might need to call
5724b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          {@link android.view.View#invalidate invalidate()} on a View to force that area of the
5734b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          screen to redraw itself with the new animated values. For example, animating the
5744b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          color property of a Drawable object only cause updates to the screen when that object
5754b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          redraws itself. All of the property setters on View,
5764b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          such as {@link android.view.View#setAlpha setAlpha()} and
5774b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          {@link android.view.View#setTranslationX setTranslationX()} invalidate the View
5784b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          properly, so you do not need to invalidate the View when calling these methods with new values.
5794b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly          </p>
5804b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
5814b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        </li>
5824b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      </ul>
5834b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    </li>
5844b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  </ul>
5854b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
5864b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly<p>You can extend the {@link android.animation.AnimatorListenerAdapter} class instead of
5874b3e912102d92c3555aae362da67178dcf5bcc55Robert Lyimplementing the {@link android.animation.Animator.AnimatorListener} interface, if you do not
5884b3e912102d92c3555aae362da67178dcf5bcc55Robert Lywant to implement all of the methods of the {@link android.animation.Animator.AnimatorListener}
5894b3e912102d92c3555aae362da67178dcf5bcc55Robert Lyinterface. The {@link android.animation.AnimatorListenerAdapter} class provides empty
5904b3e912102d92c3555aae362da67178dcf5bcc55Robert Lyimplementations of the methods that you can choose to override.</p>
5914b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>For example, the <a href=
5924b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  "{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/animation/BouncingBalls.html">Bouncing
5934b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  Balls</a> sample in the API demos creates an {@link android.animation.AnimatorListenerAdapter}
5944b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  for just the {@link android.animation.Animator.AnimatorListener#onAnimationEnd onAnimationEnd()}
5954b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  callback:</p>
5964b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <pre>
5974b3e912102d92c3555aae362da67178dcf5bcc55Robert LyValueAnimatorAnimator fadeAnim = ObjectAnimator.ofFloat(newBall, "alpha", 1f, 0f);
5984b3e912102d92c3555aae362da67178dcf5bcc55Robert LyfadeAnim.setDuration(250);
5994b3e912102d92c3555aae362da67178dcf5bcc55Robert LyfadeAnim.addListener(new AnimatorListenerAdapter() {
6004b3e912102d92c3555aae362da67178dcf5bcc55Robert Lypublic void onAnimationEnd(Animator animation) {
6014b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    balls.remove(((ObjectAnimator)animation).getTarget());
6024b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly}
6034b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly</pre>
6044b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
6054b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
6064b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <h2 id="layout">Animating Layout Changes to ViewGroups</h2>
6074b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
6084b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>The property animation system provides the capability to animate changes to ViewGroup objects
6094b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  as well as provide an easy way to animate View objects themselves.</p>
6104b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
6114b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>You can animate layout changes within a ViewGroup with the {@link
6124b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.animation.LayoutTransition} class. Views inside a ViewGroup can go through an appearing
6134b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  and disappearing animation when you add them to or remove them from a ViewGroup or when you call
6144b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  a View's {@link android.view.View#setVisibility setVisibility()} method with {@link
6154b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.view.View#VISIBLE}, android.view.View#INVISIBLE}, or {@link android.view.View#GONE}. The remaining Views in the
6164b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  ViewGroup can also animate into their new positions when you add or remove Views. You can define
6174b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  the following animations in a {@link android.animation.LayoutTransition} object by calling {@link
6184b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.animation.LayoutTransition#setAnimator setAnimator()} and passing in an {@link
6194b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.animation.Animator} object with one of the following {@link
6204b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.animation.LayoutTransition} constants:</p>
6214b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
6224b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <ul>
6234b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <li><code>APPEARING</code> - A flag indicating the animation that runs on items that are
6244b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    appearing in the container.</li>
6254b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
6264b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <li><code>CHANGE_APPEARING</code> - A flag indicating the animation that runs on items that are
6274b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    changing due to a new item appearing in the container.</li>
6284b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
6294b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <li><code>DISAPPEARING</code> - A flag indicating the animation that runs on items that are
6304b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    disappearing from the container.</li>
6314b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
6324b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <li><code>CHANGE_DISAPPEARING</code> - A flag indicating the animation that runs on items that
6334b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    are changing due to an item disappearing from the container.</li>
6344b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  </ul>
6354b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
6364b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>You can define your own custom animations for these four types of events to customize the look
6374b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  of your layout transitions or just tell the animation system to use the default animations.</p>
6384b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
6394b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>The <a href=
6404b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  "{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/animation/LayoutAnimations.html">
6414b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  LayoutAnimations</a> sample in API Demos shows you how to define animations for layout
6424b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  transitions and then set the animations on the View objects that you want to animate.</p>
6434b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
6444b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>The <a href=
6454b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  "{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/animation/LayoutAnimationsByDefault.html">
6464b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  LayoutAnimationsByDefault</a> and its corresponding <a href=
6474b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  "{@docRoot}resources/samples/ApiDemos/res/layout/layout_animations_by_default.html">layout_animations_by_default.xml</a>
6484b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  layout resource file show you how to enable the default layout transitions for ViewGroups in XML.
6494b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  The only thing that you need to do is to set the <code>android:animateLayoutchanges</code>
6504b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  attribute to <code>true</code> for the ViewGroup. For example:</p>
6514b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <pre>
6524b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly&lt;LinearLayout
6534b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    android:orientation="vertical"
6544b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    android:layout_width="wrap_content"
6554b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    android:layout_height="match_parent"
6564b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    android:id="@+id/verticalContainer"
6574b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    android:animateLayoutChanges="true" /&gt;
6584b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly</pre>
6594b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
6604b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>Setting this attribute to true automatically animates Views that are added or removed from the
6614b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  ViewGroup as well as the remaining Views in the ViewGroup.</p>
6624b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
6634b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <h2 id="type-evaluator">Using a TypeEvaluator</h2>
6644b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
6654b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>If you want to animate a type that is unknown to the Android system, you can create your own
6664b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  evaluator by implementing the {@link android.animation.TypeEvaluator} interface. The types that
6674b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  are known by the Android system are <code>int</code>, <code>float</code>, or a color, which are
6684b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  supported by the {@link android.animation.IntEvaluator}, {@link
6694b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.animation.FloatEvaluator}, and {@link android.animation.ArgbEvaluator} type
6704b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  evaluators.</p>
6714b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
6724b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>There is only one method to implement in the {@link android.animation.TypeEvaluator}
6734b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  interface, the {@link android.animation.TypeEvaluator#evaluate evaluate()} method. This allows
6744b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  the animator that you are using to return an appropriate value for your animated property at the
6754b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  current point of the animation. The {@link android.animation.FloatEvaluator} class demonstrates
6764b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  how to do this:</p>
6774b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <pre>
6784b3e912102d92c3555aae362da67178dcf5bcc55Robert Lypublic class FloatEvaluator implements TypeEvaluator {
6794b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
6804b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    public Object evaluate(float fraction, Object startValue, Object endValue) {
6814b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        float startFloat = ((Number) startValue).floatValue();
6824b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        return startFloat + fraction * (((Number) endValue).floatValue() - startFloat);
6834b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    }
6844b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly}
6854b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly</pre>
6864b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
6874b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p class="note"><strong>Note:</strong> When {@link android.animation.ValueAnimator} (or {@link
6884b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.animation.ObjectAnimator}) runs, it calculates a current elapsed fraction of the
6894b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  animation (a value between 0 and 1) and then calculates an interpolated version of that depending
6904b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  on what interpolator that you are using. The interpolated fraction is what your {@link
6914b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.animation.TypeEvaluator} receives through the <code>fraction</code> parameter, so you do
6924b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  not have to take into account the interpolator when calculating animated values.</p>
6934b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
6944b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <h2 id="interpolators">Using Interpolators</h2>
6954b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
6964b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>An interpolator define how specific values in an animation are calculated as a function of
6974b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  time. For example, you can specify animations to happen linearly across the whole animation,
6984b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  meaning the animation moves evenly the entire time, or you can specify animations to use
6994b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  non-linear time, for example, using acceleration or deceleration at the beginning or end of the
7004b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  animation.</p>
7014b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
7024b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>Interpolators in the animation system receive a fraction from Animators that represent the
7034b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  elapsed time of the animation. Interpolators modify this fraction to coincide with the type of
7044b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  animation that it aims to provide. The Android system provides a set of common interpolators in
7054b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  the {@link android.view.animation android.view.animation package}. If none of these suit your
7064b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  needs, you can implement the {@link android.animation.TimeInterpolator} interface and create your
7074b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  own.</p>
7084b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
7094b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>As an example, how the default interpolator {@link
7104b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.view.animation.AccelerateDecelerateInterpolator} and the {@link
7114b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.view.animation.LinearInterpolator} calculate interpolated fractions are compared below.
7124b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  The {@link android.view.animation.LinearInterpolator} has no effect on the elapsed fraction. The {@link
7134b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.view.animation.AccelerateDecelerateInterpolator} accelerates into the animation and
7144b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  decelerates out of it. The following methods define the logic for these interpolators:</p>
7154b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
7164b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p><strong>AccelerateDecelerateInterpolator</strong></p>
7174b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <pre>
7184b3e912102d92c3555aae362da67178dcf5bcc55Robert Lypublic float getInterpolation(float input) {
7194b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    return (float)(Math.cos((input + 1) * Math.PI) / 2.0f) + 0.5f;
7204b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly}
7214b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly</pre>
7224b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
7234b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p><strong>LinearInterpolator</strong></p>
7244b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <pre>
7254b3e912102d92c3555aae362da67178dcf5bcc55Robert Lypublic float getInterpolation(float input) {
7264b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    return input;
7274b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly}
7284b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly</pre>
7294b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
7304b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>The following table represents the approximate values that are calculated by these
7314b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  interpolators for an animation that lasts 1000ms:</p>
7324b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
7334b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <table>
7344b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <tr>
7354b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <th>ms elapsed</th>
7364b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
7374b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <th>Elapsed fraction/Interpolated fraction (Linear)</th>
7384b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
7394b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <th>Interpolated fraction (Accelerate/Decelerate)</th>
7404b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    </tr>
7414b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
7424b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <tr>
7434b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <td>0</td>
7444b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
7454b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <td>0</td>
7464b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
7474b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <td>0</td>
7484b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    </tr>
7494b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
7504b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <tr>
7514b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <td>200</td>
7524b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
7534b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <td>.2</td>
7544b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
7554b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <td>.1</td>
7564b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    </tr>
7574b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
7584b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <tr>
7594b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <td>400</td>
7604b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
7614b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <td>.4</td>
7624b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
7634b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <td>.345</td>
7644b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    </tr>
7654b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
7664b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <tr>
7674b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <td>600</td>
7684b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
7694b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <td>.6</td>
7704b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
7714b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <td>.8</td>
7724b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    </tr>
7734b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
7744b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <tr>
7754b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <td>800</td>
7764b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
7774b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <td>.8</td>
7784b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
7794b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <td>.9</td>
7804b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    </tr>
7814b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
7824b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <tr>
7834b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <td>1000</td>
7844b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
7854b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <td>1</td>
7864b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
7874b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly      <td>1</td>
7884b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    </tr>
7894b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  </table>
7904b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
7914b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>As the table shows, the {@link android.view.animation.LinearInterpolator} changes the values
7924b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  at the same speed, .2 for every 200ms that passes. The {@link
7934b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.view.animation.AccelerateDecelerateInterpolator} changes the values faster than {@link
7944b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.view.animation.LinearInterpolator} between 200ms and 600ms and slower between 600ms and
7954b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  1000ms.</p>
7964b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
7974b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <h2 id="keyframes">Specifying Keyframes</h2>
7984b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
7994b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>A {@link android.animation.Keyframe} object consists of a time/value pair that lets you define
8004b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  a specific state at a specific time of an animation. Each keyframe can also have its own
8014b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  interpolator to control the behavior of the animation in the interval between the previous
8024b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  keyframe's time and the time of this keyframe.</p>
8034b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
8044b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>To instantiate a {@link android.animation.Keyframe} object, you must use one of the factory
8054b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  methods, {@link android.animation.Keyframe#ofInt ofInt()}, {@link
8064b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.animation.Keyframe#ofFloat ofFloat()}, or {@link android.animation.Keyframe#ofObject
8074b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  ofObject()} to obtain the appropriate type of {@link android.animation.Keyframe}. You then call
8084b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  the {@link android.animation.PropertyValuesHolder#ofKeyframe ofKeyframe()} factory method to
8094b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  obtain a {@link android.animation.PropertyValuesHolder} object. Once you have the object, you can
8104b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  obtain an animator by passing in the {@link android.animation.PropertyValuesHolder} object and
8114b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  the object to animate. The following code snippet demonstrates how to do this:</p>
8124b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <pre>
8134b3e912102d92c3555aae362da67178dcf5bcc55Robert LyKeyframe kf0 = Keyframe.ofFloat(0f, 0f);
8144b3e912102d92c3555aae362da67178dcf5bcc55Robert LyKeyframe kf1 = Keyframe.ofFloat(.5f, 360f);
8154b3e912102d92c3555aae362da67178dcf5bcc55Robert LyKeyframe kf2 = Keyframe.ofFloat(1f, 0f);
8164b3e912102d92c3555aae362da67178dcf5bcc55Robert LyPropertyValuesHolder pvhRotation = PropertyValuesHolder.ofKeyframe("rotation", kf0, kf1, kf2);
8174b3e912102d92c3555aae362da67178dcf5bcc55Robert LyObjectAnimator rotationAnim = ObjectAnimator.ofPropertyValuesHolder(target, pvhRotation)
8184b3e912102d92c3555aae362da67178dcf5bcc55Robert LyrotationAnim.setDuration(5000ms);
8194b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly</pre>
8204b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
8214b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>For a more complete example on how to use keyframes, see the <a href=
8224b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  "{@docRoot}resources/samples/ApiDemos/src/com/example/android/apis/animation/MultiPropertyAnimation.html">
8234b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  MultiPropertyAnimation</a> sample in APIDemos.</p>
8244b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
8254b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <h2 id="views">Animating Views</h2>
8264b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
8273b9f0aa058e95fa0c998f787a8f4f7225e9850c0kmccormick  <p>The property animation system allow streamlined animation of View objects and offers
8284b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  a few advantages over the view animation system. The view
8294b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  animation system transformed View objects by changing the way that they were drawn. This was
8304b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  handled in the container of each View, because the View itself had no properties to manipulate.
8314b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  This resulted in the View being animated, but caused no change in the View object itself. This
8324b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  led to behavior such as an object still existing in its original location, even though it was
8334b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  drawn on a different location on the screen. In Android 3.0, new properties and the corresponding
8344b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  getter and setter methods were added to eliminate this drawback.</p>
8354b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>The property animation system
8364b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  can animate Views on the screen by changing the actual properties in the View objects. In
8374b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  addition, Views also automatically call the {@link android.view.View#invalidate invalidate()}
8384b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  method to refresh the screen whenever its properties are changed. The new properties in the {@link
8394b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.view.View} class that facilitate property animations are:</p>
8404b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
8414b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <ul>
8424b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <li><code>translationX</code> and <code>translationY</code>: These properties control where the
8434b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    View is located as a delta from its left and top coordinates which are set by its layout
8444b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    container.</li>
8454b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
8464b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <li><code>rotation</code>, <code>rotationX</code>, and <code>rotationY</code>: These properties
8474b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    control the rotation in 2D (<code>rotation</code> property) and 3D around the pivot point.</li>
8484b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
8494b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <li><code>scaleX</code> and <code>scaleY</code>: These properties control the 2D scaling of a
8504b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    View around its pivot point.</li>
8514b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
8524b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <li><code>pivotX</code> and <code>pivotY</code>: These properties control the location of the
8534b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    pivot point, around which the rotation and scaling transforms occur. By default, the pivot
8544b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    point is located at the center of the object.</li>
8554b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
8564b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <li><code>x</code> and <code>y</code>: These are simple utility properties to describe the
8574b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    final location of the View in its container, as a sum of the left and top values and
8584b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    translationX and translationY values.</li>
8594b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
8604b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <li><code>alpha</code>: Represents the alpha transparency on the View. This value is 1 (opaque)
8614b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    by default, with a value of 0 representing full transparency (not visible).</li>
8624b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  </ul>
8634b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
8644b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>To animate a property of a View object, such as its color or rotation value, all you need to
8654b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  do is create a property animator and specify the View property that you want to
8664b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  animate. For example:</p>
8674b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <pre>
8684b3e912102d92c3555aae362da67178dcf5bcc55Robert LyObjectAnimator.ofFloat(myView, "rotation", 0f, 360f);
8694b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly</pre>
8704b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
8714b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly<p>For more information on creating animators, see the sections on animating with
8724b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly<a href="#value-animator">ValueAnimator</a> and <a href="#object-animator">ObjectAnimator</a>.
8734b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly</p>
8744b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
8754b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly<h3 id="view-prop-animator">Animating with ViewPropertyAnimator</h3>
8764b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly<p>The {@link android.view.ViewPropertyAnimator} provides a simple way to animate several
8774b3e912102d92c3555aae362da67178dcf5bcc55Robert Lyproperties of a {@link android.view.View} in parallel, using a single underlying {@link
8784b3e912102d92c3555aae362da67178dcf5bcc55Robert Lyandroid.animation.Animator}
8794b3e912102d92c3555aae362da67178dcf5bcc55Robert Lyobject. It behaves much like an {@link android.animation.ObjectAnimator}, because it modifies the
8804b3e912102d92c3555aae362da67178dcf5bcc55Robert Lyactual values of the view's properties, but is more efficient when animating many properties at
8814b3e912102d92c3555aae362da67178dcf5bcc55Robert Lyonce. In addition, the code for using the {@link android.view.ViewPropertyAnimator} is much
8824b3e912102d92c3555aae362da67178dcf5bcc55Robert Lymore concise and easier to read. The following code snippets show the differences in using multiple
8834b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly{@link android.animation.ObjectAnimator} objects, a single
8844b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly{@link android.animation.ObjectAnimator}, and the {@link android.view.ViewPropertyAnimator} when
8854b3e912102d92c3555aae362da67178dcf5bcc55Robert Lysimultaneously animating the <code>x</code> and <code>y</code> property of a view.</p>
8864b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
8874b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly<p><strong>Multiple ObjectAnimator objects</strong></p>
8884b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly<pre>
8894b3e912102d92c3555aae362da67178dcf5bcc55Robert LyObjectAnimator animX = ObjectAnimator.ofFloat(myView, "x", 50f);
8904b3e912102d92c3555aae362da67178dcf5bcc55Robert LyObjectAnimator animY = ObjectAnimator.ofFloat(myView, "y", 100f);
8914b3e912102d92c3555aae362da67178dcf5bcc55Robert LyAnimatorSet animSetXY = new AnimatorSet();
8924b3e912102d92c3555aae362da67178dcf5bcc55Robert LyanimSetXY.playTogether(animX, animY);
8934b3e912102d92c3555aae362da67178dcf5bcc55Robert LyanimSetXY.start();
8944b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly</pre>
8954b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
8964b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly<p><strong>One ObjectAnimator</strong></p>
8974b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly<pre>
8984b3e912102d92c3555aae362da67178dcf5bcc55Robert LyPropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("x", 50f);
8994b3e912102d92c3555aae362da67178dcf5bcc55Robert LyPropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("y", 100f);
9004b3e912102d92c3555aae362da67178dcf5bcc55Robert LyObjectAnimator.ofPropertyValuesHolder(myView, pvhX, pvyY).start();
9014b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly</pre>
9024b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
9034b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly<p><strong>ViewPropertyAnimator</strong></p>
9044b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly<pre>
9054b3e912102d92c3555aae362da67178dcf5bcc55Robert LymyView.animate().x(50f).y(100f);
9064b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly</pre>
9074b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
9084b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly<p>
9094b3e912102d92c3555aae362da67178dcf5bcc55Robert LyFor more detailed information about {@link
9104b3e912102d92c3555aae362da67178dcf5bcc55Robert Lyandroid.view.ViewPropertyAnimator}, see the corresponding Android Developers
9114b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly<a href="http://android-developers.blogspot.com/2011/05/introducing-viewpropertyanimator.html">blog
9124b3e912102d92c3555aae362da67178dcf5bcc55Robert Lypost</a>.</p>
9134b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
9144b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly<h2 id="declaring-xml">Declaring Animations in XML</h2>
9154b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
9164b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>The property animation system lets you declare property animations with XML instead of doing
9174b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  it programmatically. By defining your animations in XML, you can easily reuse your animations
9184b3e912102d92c3555aae362da67178dcf5bcc55Robert Lyin multiple activities and more easily edit the animation sequence.</p>
9194b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
9204b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly<p>To distinguish animation files that use the new property animation APIs from those that use the
9214b3e912102d92c3555aae362da67178dcf5bcc55Robert Lylegacy <a href="{@docRoot}guide/topics/graphics/view-animation.html">view animation</a> framework,
9224b3e912102d92c3555aae362da67178dcf5bcc55Robert Lystarting with Android 3.1, you should save the XML files for property animations in the {@code
9234b3e912102d92c3555aae362da67178dcf5bcc55Robert Lyres/animator/} directory (instead of {@code res/anim/}). Using the {@code animator} directory name
9244b3e912102d92c3555aae362da67178dcf5bcc55Robert Lyis optional, but necessary if you want to use the layout editor tools in the Eclipse ADT plugin (ADT
9254b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly11.0.0+), because ADT only searches the {@code res/animator/} directory for property animation
9264b3e912102d92c3555aae362da67178dcf5bcc55Robert Lyresources.</p>
9274b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
9284b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly<p>The following property animation classes have XML declaration support with the
9294b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  following XML tags:</p>
9304b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
9314b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <ul>
9324b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <li>{@link android.animation.ValueAnimator} - <code>&lt;animator&gt;</code></li>
9334b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
9344b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <li>{@link android.animation.ObjectAnimator} - <code>&lt;objectAnimator&gt;</code></li>
9354b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
9364b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    <li>{@link android.animation.AnimatorSet} - <code>&lt;set&gt;</code></li>
9374b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  </ul>
9384b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
9394b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly<p>The following example plays the two sets of object animations sequentially, with the first nested
9404b3e912102d92c3555aae362da67178dcf5bcc55Robert Lyset playing two object animations together:</p>
9414b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
9424b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly<pre>
9434b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly&lt;set android:ordering="sequentially"&gt;
9444b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    &lt;set&gt;
9454b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        &lt;objectAnimator
9464b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly            android:propertyName="x"
9474b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly            android:duration="500"
9484b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly            android:valueTo="400"
9494b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly            android:valueType="intType"/&gt;
9504b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        &lt;objectAnimator
9514b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly            android:propertyName="y"
9524b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly            android:duration="500"
9534b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly            android:valueTo="300"
9544b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly            android:valueType="intType"/&gt;
9554b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    &lt;/set&gt;
9564b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    &lt;objectAnimator
9574b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        android:propertyName="alpha"
9584b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        android:duration="500"
9594b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly        android:valueTo="1f"/&gt;
9604b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly&lt;/set&gt;
9614b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly</pre>
9624b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  <p>In order to run this animation, you must inflate the XML resources in your code to an {@link
9634b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.animation.AnimatorSet} object, and then set the target objects for all of the animations
9644b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  before starting the animation set. Calling {@link android.animation.AnimatorSet#setTarget
9654b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  setTarget()} sets a single target object for all children of the {@link
9664b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly  android.animation.AnimatorSet} as a convenience. The following code shows how to do this:</p>
9674b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
9684b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly<pre>
9694b3e912102d92c3555aae362da67178dcf5bcc55Robert LyAnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(myContext,
9704b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly    R.anim.property_animator);
9714b3e912102d92c3555aae362da67178dcf5bcc55Robert Lyset.setTarget(myObject);
9724b3e912102d92c3555aae362da67178dcf5bcc55Robert Lyset.start();
9734b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly</pre>
9744b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
9754b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly<p>For information about the XML syntax for defining property animations, see <a
9764b3e912102d92c3555aae362da67178dcf5bcc55Robert Lyhref="{@docRoot}guide/topics/resources/animation-resource.html#Property">Animation Resources</a>.
9774b3e912102d92c3555aae362da67178dcf5bcc55Robert Ly
978