Using AnimationSet : AnimationSet « Animation « Android






Using AnimationSet

 
//package jp.mrshiromi.net.onamaenaani.util;

import android.content.Context;
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.ScaleAnimation;
import android.view.animation.TranslateAnimation;

class AnimUtil {

  public static final int DURATION = 10000;
  public static final int ALPHA_DURATION = 500;

  public static Animation createAnimation() {
    AnimationSet set = new AnimationSet(false);
    AlphaAnimation aa = new AlphaAnimation(0f, 1f);
    aa.setDuration(ALPHA_DURATION * 4);
    TranslateAnimation ta1 = new TranslateAnimation(
        Animation.RELATIVE_TO_PARENT, -0.1f,
        Animation.RELATIVE_TO_PARENT, 0.1f,
        Animation.RELATIVE_TO_PARENT, 0.0f,
        Animation.RELATIVE_TO_PARENT, 0.0f);
    ta1.setDuration(DURATION / 5);
    ta1.setRepeatMode(Animation.REVERSE);
    ta1.setRepeatCount(DURATION / (DURATION / 5) - 1);
    ScaleAnimation sa = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f,
        Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
        0.5f);
    sa.setDuration(DURATION - ALPHA_DURATION);
    TranslateAnimation ta2 = new TranslateAnimation(
        Animation.RELATIVE_TO_PARENT, 0f, Animation.RELATIVE_TO_PARENT,
        0f, Animation.RELATIVE_TO_PARENT, 0.8f,
        Animation.RELATIVE_TO_PARENT, 0f);
    ta2.setDuration(DURATION + ALPHA_DURATION);
    TranslateAnimation ta3 = new TranslateAnimation(
        Animation.RELATIVE_TO_PARENT, 0f, Animation.RELATIVE_TO_PARENT,
        -0.1f, Animation.RELATIVE_TO_PARENT, 0f,
        Animation.RELATIVE_TO_PARENT, 0f);
    ta3.setDuration(DURATION / 5);
    ta3.setStartOffset(DURATION);

    set.addAnimation(aa);
    set.addAnimation(ta1);
    set.addAnimation(sa);
    set.addAnimation(ta2);
    set.addAnimation(ta3);
    set.setFillAfter(true);
    return set;
  }
}

   
  








Related examples in the same category