NineOldAndroids

repository·master·Indexed 26 days ago

https://github.com/jakewharton/nineoldandroids

A deprecated library providing access to Android 3.0 (Honeycomb) animation APIs for older Android platform versions dating back to 1.0. It serves as a drop-in replacement for the native animation API, featuring classes such as KeyframeSet for interpolated values and ViewPropertyAnimatorHC for animating View properties like alpha, rotation, and translation.

Tokens
1.3K
Snippets
1
Records
10
Agent score
86%

What's inside NineOldAndroids

  1. Include NineOldAndroids in your project

    master

    You can include NineOldAndroids in your Android project using either a manual JAR inclusion or via Maven.

    Manual Installation: Download the .jar file from the GitHub downloads page and place it in your application's libs/ folder.

    Maven Dependency: If you use Maven, add the following dependency to your configuration:

    <dependency>
      <groupId>com.nineoldandroids</groupId>
      <artifactId>library</artifactId>
      <version>2.4.0</version>
    </dependency>
  2. Use NineOldAndroids animation APIs

    master

    The NineOldAndroids API is designed to be a drop-in replacement for the Honeycomb (Android 3.0) animation API. To use it, simply change your existing Android animation imports to use the com.nineoldandroids.XXX package instead of android.view.animation.XXX.

    Note: LayoutTransition is present in the library, but it cannot be fully implemented on versions prior to Android 3.0.

  3. Configure ViewPropertyAnimatorHC animation settings

    master

    You can customize the timing and behavior of the property animation using the following methods:

    • setDuration(long duration): Sets the length of the animation in milliseconds. Throws IllegalArgumentException if duration is negative.
    • getDuration(): Returns the current duration in milliseconds.
    • setStartDelay(long startDelay): Sets the delay before the animation begins in milliseconds. Throws IllegalArgumentException if delay is negative.
    • getStartDelay(): Returns the current start delay in milliseconds.
    • setInterpolator(Interpolator interpolator): Sets the interpolator for the animation.
    • setListener(Animator.AnimatorListener listener): Sets a listener to receive lifecycle events (start, end, cancel, repeat).
  4. Animate View properties (Absolute and Relative)

    master

    The following methods are available to specify which properties of the View should be animated. Each method returns the ViewPropertyAnimator instance to allow for method chaining.

    Absolute Property Methods

    These methods animate a property to a specific target value:

    • alpha(float value)
    • rotation(float value)
    • rotationX(float value)
    • rotationY(float value)
    • scaleX(float value)
    • scaleY(float value)
    • translationX(float value)
    • translationY(float value)
    • x(float value)
    • y(float value)

    Relative Property Methods (By)

    These methods animate a property by a relative offset from its current value:

    • alphaBy(float value)
    • rotationBy(float value)
    • rotationXBy(float value)
    • rotationYBy(float value)
    • scaleXBy(float value)
    • scaleYBy(float value)
    • translationXBy(float value)
    • translationYBy(float value)
    • xBy(float value)
    • yBy(float value)
  5. Configure TypeEvaluator for Object KeyframeSets

    master
    When using KeyframeSet.ofObject(...) or a generic KeyframeSet created via ofKeyframe(...) with non-primitive types, you must provide a TypeEvaluator to define how to interpolate between values. Use setEvaluator(TypeEvaluator evaluator) to assign it. Specialized IntKeyframeSet and FloatKeyframeSet do not require this as they use optimized internal evaluators.
  6. Create a KeyframeSet for animations

    master

    The KeyframeSet class is used by ValueAnimator to calculate interpolated values between keyframes. While the class itself is marked as an implementation detail, you can use its static factory methods to create specialized sets for different data types:

    • ofInt(int... values): Creates an IntKeyframeSet where values are distributed evenly across the animation timeline.
    • ofFloat(float... values): Creates a FloatKeyframeSet where values are distributed evenly across the animation timeline.
    • ofObject(Object... values): Creates a KeyframeSet for arbitrary objects, distributing values evenly.
    • ofKeyframe(Keyframe... keyframes): Creates a set from an existing array of Keyframe objects. It automatically selects the most efficient specialized set (Float or Int) if all provided keyframes are of the same primitive type.
  7. Animate View properties with ViewPropertyAnimatorHC

    master

    The ViewPropertyAnimatorHC class provides a Honeycomb-style API for animating multiple properties of an Android View simultaneously. It allows for chaining property animations (like alpha, scale, rotation, and translation) and configuring the animation's duration, start delay, and interpolator.

    Note: While the class itself is package-private, it is designed to be accessed via View.animate() in a compatible environment. The available property methods include both absolute value setters (e.g., alpha(float)) and relative offset setters (e.g., alphaBy(float)).