get Translation Value Animator - Android android.animation

Android examples for android.animation:Animator

Description

get Translation Value Animator

Demo Code


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

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

import android.view.animation.Interpolator;

public class Main {
    public static ValueAnimator getTranslationValueAnimator(
            int startX,
            int startY,
            int endX,
            int endY,
            int duration,
            Interpolator interpolator,/*w  w  w .  j ava 2  s. c  o m*/
            final ValueAnimator.AnimatorUpdateListener animatorUpdateListener,
            final Animator.AnimatorListener animatorListener) {
        PropertyValuesHolder pvhX = PropertyValuesHolder.ofInt("x", startX,
                endX);
        PropertyValuesHolder pvyY = PropertyValuesHolder.ofInt("y", startY,
                endY);
        final ValueAnimator animator = ObjectAnimator
                .ofPropertyValuesHolder(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