Example usage for android.view.animation AnimationSet addAnimation

List of usage examples for android.view.animation AnimationSet addAnimation

Introduction

In this page you can find the example usage for android.view.animation AnimationSet addAnimation.

Prototype

public void addAnimation(Animation a) 

Source Link

Document

Add a child animation to this animation set.

Usage

From source file:Main.java

public static Animation clickAnimation(float scaleXY, long durationMillis) {
    AnimationSet set = new AnimationSet(true);
    set.addAnimation(getScaleAnimation(scaleXY, durationMillis));
    set.setDuration(durationMillis);/*w  w w  .  ja va2s.  co m*/
    return set;
}

From source file:Main.java

public static AnimationSet ShuffleAnimation(int deltaX, int deltaY) {

    TranslateAnimation shake_1 = new TranslateAnimation(0, deltaX, 0, deltaY);
    shake_1.setDuration(400);/*  w w w  .  j a  v a2 s. c  o m*/
    shake_1.setStartOffset(0);
    shake_1.setFillAfter(true);
    TranslateAnimation shake_2 = new TranslateAnimation(0, -deltaX, 0, -deltaY);
    shake_2.setDuration(400);
    shake_2.setStartOffset(400);
    shake_2.setFillAfter(true);
    AnimationSet ShakeIt = new AnimationSet(true);
    ShakeIt.addAnimation(shake_1);
    ShakeIt.addAnimation(shake_2);
    ShakeIt.setInterpolator(new OvershootInterpolator());

    return ShakeIt;
}

From source file:Main.java

public static void animation(View paramView) {
    TranslateAnimation localTranslateAnimation = new TranslateAnimation(2, 1.0F, 2, 0.0F, 2, 0.0F, 2, 0.0F);
    AlphaAnimation localAlphaAnimation = new AlphaAnimation(0.0F, 1.0F);
    AnimationSet localAnimationSet = new AnimationSet(false);
    localAnimationSet.addAnimation(localTranslateAnimation);
    localAnimationSet.addAnimation(localAlphaAnimation);
    animation(paramView, localAnimationSet, 1000L, 0L);
}

From source file:Main.java

public static AnimationSet getAnimationSet(Animation... animations) {
    AnimationSet set = new AnimationSet(true);
    for (Animation animation : animations)
        set.addAnimation(animation);
    return set;//  w  ww.j av  a  2 s  .c o m
}

From source file:Main.java

public static AnimationSet RotateAndFadeInAnimation() {

    AlphaAnimation fade_in = new AlphaAnimation(0.2f, 1f);
    fade_in.setDuration(400);//from   w  ww. j  a v  a 2 s.com
    fade_in.setStartOffset(0);
    fade_in.setFillAfter(true);

    ScaleAnimation expand = new ScaleAnimation(0.2f, 1, 0.2f, 1, Animation.RELATIVE_TO_SELF, .5f,
            Animation.RELATIVE_TO_SELF, .5f);
    expand.setDuration(500);
    expand.setStartOffset(0);
    expand.setFillAfter(true);

    RotateAnimation rotate = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, .5f,
            Animation.RELATIVE_TO_SELF, .5f);
    rotate.setDuration(500);
    rotate.setStartOffset(0);
    // rotate.setInterpolator(new LinearInterpolator());
    rotate.setFillAfter(true);

    AnimationSet Reload = new AnimationSet(true);
    Reload.addAnimation(fade_in);
    Reload.addAnimation(expand);
    Reload.addAnimation(rotate);
    Reload.setInterpolator(new DecelerateInterpolator(1.3f));
    return Reload;
}

From source file:Main.java

public static AnimationSet RotateAndFadeOutAnimation() {
    AlphaAnimation fade_out = new AlphaAnimation(1f, 0.2f);
    fade_out.setDuration(500);// www. jav  a2 s.c om
    fade_out.setStartOffset(0);
    fade_out.setFillAfter(true);

    ScaleAnimation shrink = new ScaleAnimation(1f, 0.2f, 1f, 0.2f, Animation.RELATIVE_TO_SELF, .5f,
            Animation.RELATIVE_TO_SELF, .5f);
    shrink.setDuration(400);
    shrink.setStartOffset(0);
    shrink.setFillAfter(true);

    RotateAnimation rotate = new RotateAnimation(0.0f, 360f, Animation.RELATIVE_TO_SELF, .5f,
            Animation.RELATIVE_TO_SELF, .5f);
    rotate.setDuration(500);
    rotate.setStartOffset(0);
    rotate.setInterpolator(new LinearInterpolator());
    rotate.setFillAfter(true);

    AnimationSet Reload = new AnimationSet(true);
    Reload.addAnimation(fade_out);
    Reload.addAnimation(shrink);
    Reload.addAnimation(rotate);
    Reload.setInterpolator(new AccelerateInterpolator(1.1f));

    return Reload;
}

From source file:Main.java

public static AnimationSet translate(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta,
        int duration) {
    Animation animation = new TranslateAnimation(fromXDelta, toXDelta, fromYDelta, toYDelta);
    animation.setDuration(duration);//  w  ww  .  j a  v  a  2 s.co m

    AnimationSet animationSet = new AnimationSet(true);
    // animationSet.setInterpolator(new AccelerateInterpolator());
    animationSet.addAnimation(animation);
    return animationSet;
}

From source file:Main.java

public static void addAnimation(View view, Animation animation, boolean first) {
    Animation previousAnimation = view.getAnimation();
    if (previousAnimation == null || previousAnimation.getClass() == animation.getClass()) {
        if (animation.getStartTime() == Animation.START_ON_FIRST_FRAME)
            view.startAnimation(animation);
        else//from  w  w w.ja v  a  2s.  c o m
            view.setAnimation(animation);
        return;
    }

    if (!(previousAnimation instanceof AnimationSet)) {
        AnimationSet newSet = new AnimationSet(false);
        newSet.addAnimation(previousAnimation);
        previousAnimation = newSet;
    }

    // Remove old of same type
    //
    AnimationSet set = (AnimationSet) previousAnimation;
    for (int i = 0; i < set.getAnimations().size(); i++) {
        Animation anim = set.getAnimations().get(i);
        if (anim.getClass() == animation.getClass()) {
            set.getAnimations().remove(i);
            break;
        }
    }

    // Add this (first if it is a scale animation ,else at end)
    if (animation instanceof ScaleAnimation || first) {
        set.getAnimations().add(0, animation);
    } else {
        set.getAnimations().add(animation);
    }

    animation.startNow();
    view.setAnimation(set);
}

From source file:Main.java

public static GridLayoutAnimationController getLayoutAnimation() {
    AnimationSet set = new AnimationSet(true);
    Animation animation = new AlphaAnimation(0.0f, 1.0f);
    animation.setDuration(40);/*from   w ww .  j a v a  2s .co m*/
    set.addAnimation(animation);
    animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
    animation.setDuration(75);
    set.addAnimation(animation);
    GridLayoutAnimationController controller = new GridLayoutAnimationController(set);
    return controller;
}

From source file:Main.java

public static void makeViewGroupAnimation(ViewGroup viewGroup) {
    AnimationSet set = new AnimationSet(true);

    Animation animation = new AlphaAnimation(0.0f, 1.0f);
    animation.setDuration(50);//from  www. jav  a  2s  . c om
    set.addAnimation(animation);

    animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
    animation.setDuration(150);
    set.addAnimation(animation);

    LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f);
    viewGroup.setLayoutAnimation(controller);
}