get Portrait Click Animation - Android Animation

Android examples for Animation:Animation Creation

Description

get Portrait Click Animation

Demo Code


//package com.java2s;

import android.view.animation.AccelerateInterpolator;

import android.view.animation.Animation;
import android.view.animation.AnimationSet;

import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;

import android.view.animation.TranslateAnimation;

public class Main {

    public static Animation getPortraitClickAnimation() {
        AnimationSet set = new AnimationSet(false);
        set.setFillEnabled(true);//from w w  w.j a v  a2 s  .c  om
        set.setFillAfter(true);

        Animation animationRightToLeft = new TranslateAnimation(
                Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF,
                -0.2f, Animation.RELATIVE_TO_SELF, 0,
                Animation.RELATIVE_TO_SELF, 0);
        animationRightToLeft.setFillEnabled(true);
        animationRightToLeft.setFillAfter(true);
        Interpolator ait = new AccelerateInterpolator(1.5f);
        animationRightToLeft.setInterpolator(ait);
        animationRightToLeft.setDuration(400);

        Animation animationLeftToSelf = new TranslateAnimation(
                Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF,
                0.2f, Animation.RELATIVE_TO_SELF, 0,
                Animation.RELATIVE_TO_SELF, 0);
        animationLeftToSelf.setFillEnabled(true);
        animationLeftToSelf.setFillAfter(true);
        Interpolator dit = new DecelerateInterpolator(1.5f);
        animationLeftToSelf.setInterpolator(dit);
        animationLeftToSelf.setStartOffset(400);
        animationLeftToSelf.setDuration(300);

        set.addAnimation(animationRightToLeft);
        set.addAnimation(animationLeftToSelf);
        return set;
    }
}

Related Tutorials