get Resize And Translation Animator - Android android.animation

Android examples for android.animation:Animator

Description

get Resize And Translation Animator

Demo Code


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

import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.animation.ValueAnimator;

import android.support.annotation.NonNull;

import android.view.View;

import android.view.animation.Interpolator;

public class Main {
    @NonNull/*from  w  w w  .  j  a va  2 s.  com*/
    public static ValueAnimator getResizeAndTranslationAnimator(
            View view,
            long duration,
            float scale,
            float startX,
            float startY,
            float endX,
            float endY,
            Interpolator interpolator,
            final ValueAnimator.AnimatorUpdateListener animatorUpdateListener,
            final Animator.AnimatorListener animatorListener) {
        float currentScale = view.getScaleX();
        PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat(
                "scaleX", currentScale, scale);
        PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat(
                "scaleY", currentScale, scale);
        PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("x",
                startX, endX);
        PropertyValuesHolder pvyY = PropertyValuesHolder.ofFloat("y",
                startY, endY);
        final ValueAnimator animator = ObjectAnimator
                .ofPropertyValuesHolder(view, scaleX, scaleY, pvhX, pvyY)
                .setDuration(duration);
        if (interpolator != null) {
            animator.setInterpolator(interpolator);
        }
        if (animatorListener != null) {
            animator.addListener(animatorListener);
        }
        if (animatorUpdateListener != null) {
            animator.addUpdateListener(animatorUpdateListener);
        }
        return animator;
    }
}

Related Tutorials