Create open Animation - Android Animation

Android examples for Animation:Animation to Show

Description

Create open Animation

Demo Code


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

import android.view.animation.OvershootInterpolator;
import android.view.animation.RotateAnimation;

import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.RelativeLayout;

public class Main {

    public static void openAnimation(RelativeLayout relativeLayout,
            ImageView menu, long durationMillis) {
        relativeLayout.setVisibility(View.VISIBLE);
        for (int i = 1; i < relativeLayout.getChildCount(); i++) {
            ImageView imageView = null;
            if (relativeLayout.getChildAt(i) instanceof ImageView) {
                imageView = (ImageView) relativeLayout.getChildAt(i);
            } else {
                continue;
            }//from  w ww .j a v a 2s.  com

            int top = imageView.getTop();
            int left = imageView.getLeft();
            if (top == 0) {
                top = (menu.getHeight() + 50) * i;
            }
            if (left == 0) {
                left = menu.getLeft();
            }
            AnimationSet set = new AnimationSet(true);
            set.addAnimation(getRotateAnimation(-360, 0, durationMillis));
            set.addAnimation(getAlphaAnimation(0.5f, 1.0f, durationMillis));
            set.addAnimation(getTranslateAnimation(menu.getLeft() - left,
                    0, menu.getTop() - top + 30, 0, durationMillis));
            set.setFillAfter(true);
            set.setDuration(durationMillis);
            set.setStartOffset((i * 100)
                    / (-1 + relativeLayout.getChildCount()));
            set.setInterpolator(new OvershootInterpolator(1f));
            imageView.startAnimation(set);
        }
    }

    public static Animation getRotateAnimation(float fromDegrees,
            float toDegrees, long durationMillis) {
        RotateAnimation rotate = new RotateAnimation(fromDegrees,
                toDegrees, Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f);
        rotate.setDuration(durationMillis);
        rotate.setFillAfter(true);
        return rotate;
    }

    public static Animation getAlphaAnimation(float fromAlpha,
            float toAlpha, long durationMillis) {
        AlphaAnimation alpha = new AlphaAnimation(fromAlpha, toAlpha);
        alpha.setDuration(durationMillis);
        alpha.setFillAfter(true);
        return alpha;
    }

    public static Animation getTranslateAnimation(float fromXDelta,
            float toXDelta, float fromYDelta, float toYDelta,
            long durationMillis) {
        TranslateAnimation translate = new TranslateAnimation(fromXDelta,
                toXDelta, fromYDelta, toYDelta);
        translate.setDuration(durationMillis);
        translate.setFillAfter(true);
        return translate;
    }
}

Related Tutorials