ViewAnimator Documentation

repository·master·Indexed 25 days ago

https://github.com/florent37/viewanimator

A fluent Android animation library for chaining complex view animations and transitions. It supports DP values, height/width animations, color and rotation changes, custom animation logic, and pre-built enhanced animations like shake, bounceIn, and pulse.

Tokens
1.1K
Snippets
7
Records
9
Agent score
33%

What's inside ViewAnimator

  1. Animate multiple views with a fluent API

    master

    ViewAnimator allows you to chain animations for multiple views. You can use .animate() to start a sequence, .andAnimate() to add a subsequent animation for a different view, and .thenAnimate() to chain animations for the original view after the sequence. Use .start() to execute the animation set.

    ViewAnimator
           .animate(image)
                .translationY(-1000, 0)
                .alpha(0,1)
           .andAnimate(text)
                .dp().translationX(-20, 0)
                .decelerate()
                .duration(2000)
           .thenAnimate(image)
                .scale(1f, 0.5f, 1f)
                .accelerate()
                .duration(1000)
           .start();
  2. Create custom animations

    master

    Use the .custom() method to define a custom animation logic by implementing the AnimationListener.Update<T> interface. The update method provides the view and a float value (typically between 0 and 1) to drive the animation.

    ViewAnimator.animate(text)
           .custom(new AnimationListener.Update<TextView>() {
                @Override public void update(TextView view, float value) {
                      view.setText(String.format("%.02f", value));
                }
            }, 0, 1)
           .start();
  3. Animate View height and width

    master

    To animate height or width, use .waitForHeight() to wait until a ViewTreeObserver notification is received, then use .dp().width() or .dp().height() to define the animation range.

    ViewAnimator
           .animate(view)
                .waitForHeight()
                .dp().width(100,200)
                .dp().height(50,100)
                .start();
  4. Use enhanced and path animations

    master

    ViewAnimator includes several pre-built enhanced animations and support for Path animations:

    Enhanced Animations:

    • .shake()
    • .bounceIn()
    • .flash().repeatCount(n)
    • .flipHorizontal()
    • .wave()
    • .tada()
    • .pulse()
    • .standUp()
    • .swing()
    • .wobble()

    Path Animations: Pass a android.graphics.Path object to the .path(path) method.