create Pan Out Animation - Android Animation

Android examples for Animation:Alpha Fly Animation

Description

create Pan Out Animation

Demo Code


//package com.java2s;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.DecelerateInterpolator;

import android.view.animation.ScaleAnimation;

public class Main {
    private static final long MEDIUM = 500;

    public static Animation createPanOutAnim(float degree) {
        AnimationSet ret;/*w  w w .ja va2s  .c  om*/
        Animation anim;
        ret = new AnimationSet(false);

        anim = new AlphaAnimation(1f, 0f);
        anim.setDuration(MEDIUM);
        anim.setInterpolator(new DecelerateInterpolator());
        ret.addAnimation(anim);

        final float pivotX = (float) (1 + Math.cos(degree)) / 2;
        final float pivotY = (float) (1 - Math.sin(degree)) / 2;
        anim = new ScaleAnimation(1, 0.8f, 1, 0.8f,
                Animation.RELATIVE_TO_SELF, pivotX,
                Animation.RELATIVE_TO_SELF, pivotY);
        anim.setDuration(MEDIUM);
        anim.setInterpolator(new DecelerateInterpolator());
        ret.addAnimation(anim);

        return ret;
    }
}

Related Tutorials