Animates the view by translating the view in the x direction to the specified x value using the given duration. - Android Animation

Android examples for Animation:Translate Animation

Description

Animates the view by translating the view in the x direction to the specified x value using the given duration.

Demo Code


import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;

public class Main{

    public static void translationX(final View pView, final float pValue,
            final int pDuration, final Runnable pEndAction) {
        if (AndroidUtils.isUIThread()) {
            pView.animate().setDuration(pDuration).translationX(pValue)
                    .withEndAction(pEndAction);
        } else {/* w ww .j a v a 2s  .  c o  m*/
            pView.post(new Runnable() {
                public void run() {
                    translationX(pView, pValue, pDuration, pEndAction);
                }
            });
        }
    }
}

Related Tutorials