Example usage for android.view.animation TranslateAnimation setDuration

List of usage examples for android.view.animation TranslateAnimation setDuration

Introduction

In this page you can find the example usage for android.view.animation TranslateAnimation setDuration.

Prototype

public void setDuration(long durationMillis) 

Source Link

Document

How long this animation should last.

Usage

From source file:Main.java

public static Animation getTranslateLoginInAnimation(long t) {

    TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.01f,
            Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f,
            Animation.RELATIVE_TO_PARENT, 0.0f);
    animation.setDuration(t);
    return animation;
}

From source file:Main.java

/**
 * Get translate animation of PathButton.<br>
 * The visibility of path button and anchor view must be
 * {@link View#VISIBLE} or {@link View#INVISIBLE}.
 *
 * @param isOpen Is open for button/*from w w  w.  j  a v a 2s .  c om*/
 * @param button Path button
 * @param anchor Control button
 * @return Animation
 */
public static Animation animOfPathButton(boolean isOpen, View button, View anchor) {
    int[] anchorL = new int[2];
    anchor.getLocationOnScreen(anchorL);
    int[] buttonL = new int[2];
    button.getLocationOnScreen(buttonL);
    int x = anchorL[0] - buttonL[0] + (anchor.getWidth() - button.getWidth()) / 2;
    int y = anchorL[1] - buttonL[1] + (anchor.getHeight() - button.getHeight()) / 2;
    TranslateAnimation anim = new TranslateAnimation(Animation.ABSOLUTE, isOpen ? x : 0, Animation.ABSOLUTE,
            isOpen ? 0 : x, Animation.ABSOLUTE, isOpen ? y : 0, Animation.ABSOLUTE, isOpen ? 0 : y);
    anim.setDuration(300);
    anim.setFillAfter(true);
    return anim;
}

From source file:Main.java

public static void enlargeToRight(FragmentActivity activity, View view, AnimationListener listener) {

    DisplayMetrics displaymetrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int screenHeight = displaymetrics.heightPixels;
    int screenWidth = displaymetrics.widthPixels;

    AnimationSet animation = new AnimationSet(true);
    float pivotX = view.getWidth() / 2;
    float pivotY = view.getHeight() / 2;
    ScaleAnimation anim = new ScaleAnimation(0.8f, 1f, 0.8f, 1f, pivotX, pivotY);
    anim.setInterpolator(new LinearInterpolator());
    anim.setDuration(200);//www.  j av a  2  s  .c  om
    anim.setStartOffset(200);
    //anim.setFillAfter(true);
    animation.addAnimation(anim);

    TranslateAnimation animTrans = new TranslateAnimation(0.0f, (float) (screenWidth - view.getWidth()), 0.0f,
            0.0f);
    anim.setInterpolator(new LinearInterpolator());
    animTrans.setDuration(400);
    //animTrans.setStartOffset(300);
    animation.addAnimation(animTrans);

    if (listener != null)
        animation.setAnimationListener(listener);

    view.startAnimation(animation);
}

From source file:Main.java

public static void shrinkToLeft(FragmentActivity activity, View view, AnimationListener listener) {

    DisplayMetrics displaymetrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int screenHeight = displaymetrics.heightPixels;
    int screenWidth = displaymetrics.widthPixels;

    AnimationSet animation = new AnimationSet(true);
    float pivotX = view.getWidth() / 2;
    float pivotY = view.getHeight() / 2;
    ScaleAnimation anim = new ScaleAnimation(1f, 0.8f, 1f, 0.8f, pivotX, pivotY);
    anim.setInterpolator(new LinearInterpolator());
    anim.setDuration(200);//from w w  w . j  a  v a 2  s  .  c  o  m
    anim.setStartOffset(200);
    //anim.setFillAfter(true);
    animation.addAnimation(anim);

    TranslateAnimation animTrans = new TranslateAnimation(0.0f, (float) -(screenWidth - view.getWidth()), 0.0f,
            0.0f);
    anim.setInterpolator(new LinearInterpolator());
    animTrans.setDuration(400);
    //animTrans.setStartOffset(300);
    animation.addAnimation(animTrans);

    if (listener != null)
        animation.setAnimationListener(listener);

    view.startAnimation(animation);
}

From source file:Main.java

public static TranslateAnimation getTranslateAnimationToSelf(float pivotFromX, float pivotToX, float pivotFromY,
        float pivotToY, int intDuration, boolean boolFillAfter) {
    TranslateAnimation mAnmation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, pivotFromX,
            Animation.RELATIVE_TO_SELF, pivotToX, Animation.RELATIVE_TO_SELF, pivotFromY,
            Animation.RELATIVE_TO_SELF, pivotToY);
    mAnmation.setDuration(intDuration);
    mAnmation.setFillAfter(boolFillAfter);
    // mAnmation.setRepeatMode(Animation.RESTART);
    // mAnmation.setRepeatCount(intRepeatCount);
    // mAnmation.setInterpolator(AnimationUtils.loadInterpolator(mContext,
    // com.webclient.R.anim.bounce_interpolator));
    return mAnmation;
}

From source file:Main.java

public static void setTranslateAnimationToSelf(View view, float pivotFromX, float pivotToX, float pivotFromY,
        float pivotToY, int intDuration, boolean boolFillAfter) {
    TranslateAnimation mAnmation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, pivotFromX,
            Animation.RELATIVE_TO_SELF, pivotToX, Animation.RELATIVE_TO_SELF, pivotFromY,
            Animation.RELATIVE_TO_SELF, pivotToY);
    mAnmation.setDuration(intDuration);
    mAnmation.setFillAfter(boolFillAfter);
    // mAnmation.setRepeatMode(Animation.RESTART);
    // mAnmation.setRepeatCount(intRepeatCount);
    // mAnmation.setInterpolator(AnimationUtils.loadInterpolator(mContext,
    // com.webclient.R.anim.bounce_interpolator));
    view.startAnimation(mAnmation);/*w ww . ja v  a2  s  . co  m*/
}

From source file:Main.java

/**
 *    move the background view(translate animation).
 * /*  www. j  a  v  a2  s. c  om*/
 * @param view
 *          the view will be moved
 * @param durationMillis
 *          translate animation duration
 * @param fromX
 *          from X coordinate
 * @param toX
 *          to X coordinate
 * @param fromY
 *          from Y coordinate
 * @param toY
 *          to Y coordinate
 */
public static void translateFromBelow(final Context context, final View view, final long durationMillis,
        boolean fillAfter, float fromX, float toX, final float fromY, final float toY) {
    TranslateAnimation translateAnimation = new TranslateAnimation(fromX, toX, fromY, toY + 5);
    //      TranslateAnimation translateAnimation = new TranslateAnimation(fromX, toX, fromY, toY-21);
    translateAnimation.setDuration(durationMillis);
    translateAnimation.setFillAfter(fillAfter);//this animation performed will persist when it is finished
    view.startAnimation(translateAnimation);
    translateAnimation.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {

        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            //            TranslateAnimation shakeAnimation = new TranslateAnimation(0, 0, toY-21, toY+5);
            //            shakeAnimation.setInterpolator(new BounceInterpolator());
            //            shakeAnimation.setDuration(durationMillis); //500
            //            shakeAnimation.setFillAfter(true);
            //            view.startAnimation(shakeAnimation);
        }
    });
}

From source file:Main.java

public static TranslateAnimation getTranslateAnimationToParent(float pivotFromX, float pivotToX,
        float pivotFromY, float pivotToY, int intDuration, boolean boolFillAfter) {
    TranslateAnimation mAnmation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, pivotFromX,
            Animation.RELATIVE_TO_PARENT, pivotToX, Animation.RELATIVE_TO_PARENT, pivotFromY,
            Animation.RELATIVE_TO_PARENT, pivotToY);
    mAnmation.setDuration(intDuration);
    mAnmation.setFillAfter(boolFillAfter);
    // mAnmation.setRepeatMode(Animation.RESTART);
    // mAnmation.setRepeatCount(intRepeatCount);
    // mAnmation.setInterpolator(AnimationUtils.loadInterpolator(mContext,
    // com.webclient.R.anim.bounce_interpolator));
    return mAnmation;
}

From source file:Main.java

public static void setTranslateAnimationToParent(View view, float pivotFromX, float pivotToX, float pivotFromY,
        float pivotToY, int intDuration, boolean boolFillAfter) {
    TranslateAnimation mAnmation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, pivotFromX,
            Animation.RELATIVE_TO_PARENT, pivotToX, Animation.RELATIVE_TO_PARENT, pivotFromY,
            Animation.RELATIVE_TO_PARENT, pivotToY);
    mAnmation.setDuration(intDuration);
    mAnmation.setFillAfter(boolFillAfter);
    // mAnmation.setRepeatMode(Animation.RESTART);
    // mAnmation.setRepeatCount(intRepeatCount);
    // mAnmation.setInterpolator(AnimationUtils.loadInterpolator(mContext,
    // com.webclient.R.anim.bounce_interpolator));
    view.startAnimation(mAnmation);/* ww  w  . ja  v a  2  s. c  om*/
}

From source file:Main.java

private static void ApplyHorizontalScrollAnimation(View view, boolean left, int speed) {
    float sign = left ? 1f : -1f;
    AnimationSet animationSet = new AnimationSet(true);
    animationSet.setRepeatCount(Animation.INFINITE);
    animationSet.setRepeatMode(Animation.RESTART);

    TranslateAnimation move = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, sign * 0.70f,
            Animation.RELATIVE_TO_PARENT, sign * -0.70f, Animation.RELATIVE_TO_PARENT, 0,
            Animation.RELATIVE_TO_PARENT, 0);
    move.setStartOffset(0);//from w w w.  ja v a  2 s. co  m
    move.setDuration(speed);
    move.setFillAfter(true);
    animationSet.addAnimation(move);
    view.startAnimation(animationSet);
}