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