Animator to animate X scale of the view with ObjectAnimator. - Android Animation

Android examples for Animation:Scale Animation

Description

Animator to animate X scale of the view with ObjectAnimator.

Demo Code


//package com.java2s;
import android.animation.Animator;
import android.animation.ObjectAnimator;

import android.support.annotation.NonNull;
import android.view.View;

public class Main {
    /**// w  ww  .  j  a v  a  2  s  .  co  m
     * Animator to animate X scale of the view. Y scale is constant
     *
     * @param view View to be animated
     * @param pivotX x coordinate of the pivot
     * @param pivotY y coordinate of the pivot
     * @param fromScale initial scale
     * @param toScale final scale
     * @param duration animation duration in milliseconds
     * @return Animator Object
     */
    @NonNull
    public static Animator scaleX(@NonNull View view, int pivotX,
            int pivotY, float fromScale, float toScale, int duration) {
        view.setPivotX(pivotX);
        view.setPivotY(pivotY);
        Animator animator = ObjectAnimator.ofFloat(view, "scaleX",
                fromScale, toScale);
        animator.setDuration(duration);
        return animator;
    }
}

Related Tutorials