translate X Animation - Android Animation

Android examples for Animation:Translate Animation

Description

translate X Animation

Demo Code


//package com.java2s;

import android.animation.ObjectAnimator;
import android.annotation.TargetApi;

import android.os.Build;

import android.view.View;

import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;

public class Main {
    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public static void translateX(final View mCardNumberInput,
            final float src, final float length, int animationDurationMedium) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            ObjectAnimator/* ww w. ja v a  2s.com*/
                    .ofFloat(mCardNumberInput, "translationX", length)
                    .setDuration(2000).start();
        } else {
            TranslateAnimation ta = new TranslateAnimation(src, length, 0,
                    0);
            ta.setDuration(animationDurationMedium);
            ta.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    mCardNumberInput.setTranslationX(length);
                }
            });
            mCardNumberInput.startAnimation(ta);
        }
    }
}

Related Tutorials