Example usage for android.view View startAnimation

List of usage examples for android.view View startAnimation

Introduction

In this page you can find the example usage for android.view View startAnimation.

Prototype

public void startAnimation(Animation animation) 

Source Link

Document

Start the specified animation now.

Usage

From source file:Main.java

public static void collapse(final View v, boolean isHalf) {
    final int initialHeight = v.getMeasuredHeight();

    remainHeigt = 0;//w w w  .j  a v  a  2s.  com
    if (isHalf) {
        remainHeigt = initialHeight / 2;
    } else {
        remainHeigt = initialHeight;
    }

    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime == 1) {
                v.setVisibility(View.GONE);
            } else {
                v.getLayoutParams().height = initialHeight - (int) (remainHeigt * interpolatedTime);
                v.requestLayout();
            }
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    // 1dp/ms
    a.setDuration((int) (initialHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}

From source file:Main.java

protected static void show(final View view) {
    Animation fadeIn = new AlphaAnimation(0, 1);
    fadeIn.setStartOffset(500);/*from w w w.  j a v  a2 s.c o  m*/
    fadeIn.setDuration(500);

    Animation collapse = new ScaleAnimation(1, 1, 0, 1);
    collapse.setDuration(500);

    AnimationSet animation = new AnimationSet(false);
    animation.setInterpolator(new AccelerateInterpolator());
    animation.addAnimation(collapse);
    animation.addAnimation(fadeIn);

    animation.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
            view.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            view.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });

    view.startAnimation(animation);
}

From source file:Main.java

public void startAnimation(View view) {
    view.startAnimation(animation);
}

From source file:Main.java

public static void expand(final View v) {
    v.measure(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    final int targetHeight = v.getMeasuredHeight();

    // Older versions of android (pre API 21) cancel animations for views with a height of 0.
    v.getLayoutParams().height = 1;/*from  w  ww .  java2 s.co  m*/
    v.setVisibility(View.VISIBLE);
    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            v.getLayoutParams().height = interpolatedTime == 1 ? RelativeLayout.LayoutParams.WRAP_CONTENT
                    : (int) (targetHeight * interpolatedTime);
            v.requestLayout();
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    // 1dp/ms
    a.setDuration((int) (targetHeight / v.getContext().getResources().getDisplayMetrics().density) * 2);
    v.startAnimation(a);
}

From source file:Main.java

public static void collapse(final View view, final AnimationListener animationListener) {
    if (view == null) {
        return;//w ww  .ja  va2s  . c  o  m
    }

    final int initialHeight = view.getMeasuredHeight();

    final Animation animation = new Animation() {
        @Override
        protected void applyTransformation(final float interpolatedTime, final Transformation t) {
            if (interpolatedTime == 1) {
                view.setVisibility(View.GONE);
            } else {
                setHeight(view, initialHeight - (int) (initialHeight * interpolatedTime));
                view.requestLayout();
            }
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    animation.setDuration(ANIMATION_DURATION);
    // return animation;
    if (animationListener != null) {
        animation.setAnimationListener(animationListener);
    }
    view.startAnimation(animation);
}

From source file:com.example.leebeomwoo.viewbody_final.MainActivity.java

public static void startAlphaAnimation(View v, long duration, int visibility) {
    AlphaAnimation alphaAnimation = (visibility == View.VISIBLE) ? new AlphaAnimation(0f, 1f)
            : new AlphaAnimation(1f, 0f);
    alphaAnimation.setDuration(duration);
    alphaAnimation.setFillAfter(true);/*from w w w  . jav a  2 s  . co m*/
    v.startAnimation(alphaAnimation);
}

From source file:Main.java

public void startAnimation(View view) {
    animation.reset();
    view.clearAnimation();
    view.startAnimation(animation);
}

From source file:Main.java

public static void expandOrCollapse(final View v, boolean expand) {
    TranslateAnimation anim;/*from w w w. j  a va2s  . co  m*/
    if (expand) {
        anim = new TranslateAnimation(0.0f, 0.0f, -v.getHeight(), 0.0f);
        v.setVisibility(View.VISIBLE);
    } else {
        anim = new TranslateAnimation(0.0f, 0.0f, 0.0f, -v.getHeight());
        Animation.AnimationListener collapselistener = new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                // Useless
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                // Useless
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                v.setVisibility(View.GONE);
            }
        };

        anim.setAnimationListener(collapselistener);
    }

    anim.setDuration(300);
    anim.setInterpolator(new AccelerateInterpolator(0.5f));
    v.startAnimation(anim);
}

From source file:Main.java

public static void shakeAnimation(final View v) {
    float rotate = 0;
    int c = mCount++ % 5;
    if (c == 0) {
        rotate = DEGREE_0;//w ww  .  j a  v  a2 s .c  om
    } else if (c == 1) {
        rotate = DEGREE_1;
    } else if (c == 2) {
        rotate = DEGREE_2;
    } else if (c == 3) {
        rotate = DEGREE_3;
    } else {
        rotate = DEGREE_4;
    }
    final RotateAnimation mra = new RotateAnimation(rotate, -rotate, ICON_WIDTH * mDensity / 2,
            ICON_HEIGHT * mDensity / 2);
    final RotateAnimation mrb = new RotateAnimation(-rotate, rotate, ICON_WIDTH * mDensity / 2,
            ICON_HEIGHT * mDensity / 2);

    mra.setDuration(ANIMATION_DURATION);
    mrb.setDuration(ANIMATION_DURATION);

    mra.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationEnd(Animation animation) {
            if (mNeedShake) {
                mra.reset();
                v.startAnimation(mrb);
            }
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }

        @Override
        public void onAnimationStart(Animation animation) {

        }

    });

    mrb.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationEnd(Animation animation) {
            if (mNeedShake) {
                mrb.reset();
                v.startAnimation(mra);
            }
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }

        @Override
        public void onAnimationStart(Animation animation) {

        }

    });
    v.startAnimation(mra);
}

From source file:com.breadwallet.tools.animation.BRAnimator.java

public static void scaleView(View v, float startScaleX, float endScaleX, float startScaleY, float endScaleY) {
    Animation anim = new ScaleAnimation(startScaleX, endScaleX, // Start and end values for the X axis scaling
            startScaleY, endScaleY, // Start and end values for the Y axis scaling
            Animation.RELATIVE_TO_SELF, 0.5f, // Pivot point of X scaling
            Animation.RELATIVE_TO_SELF, 0.5f); // Pivot point of Y scaling
    anim.setFillAfter(true); // Needed to keep the result of the animation
    v.startAnimation(anim);
}