List of usage examples for android.view.animation TranslateAnimation TranslateAnimation
public TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)
From source file:Main.java
public static void linearAnimation(final View view, final int startX, final int startY, final int endX, final int endY, long duration, final Runnable callback) { Animation anim = new TranslateAnimation(startX, endX, startY, endY); anim.setDuration(duration);/* w w w.j av a2s . com*/ anim.setInterpolator(new DecelerateInterpolator()); view.startAnimation(anim); anim.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { view.clearAnimation(); view.setX(view.getX() + endX); view.setY(view.getY() + endY); if (callback != null) callback.run(); } @Override public void onAnimationRepeat(Animation animation) { } }); }
From source file:Main.java
public static void translateY(final View view, float fromY, float toY, long duration) { if (Build.VERSION.SDK_INT >= 12) { if (duration == 0) view.setTranslationY(toY);/*from w ww . ja v a 2 s. c o m*/ else view.animate().translationY(toY).setDuration(duration).start(); } else { TranslateAnimation translate = new TranslateAnimation(0, 0, fromY, toY); translate.setDuration(duration); translate.setFillEnabled(true); translate.setFillBefore(true); translate.setFillAfter(true); addAnimation(view, translate); } }
From source file:Main.java
/** * move the background view(translate animation). * // w ww . j a va2 s . c o m * @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 translateFromAbove(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.setInterpolator(new BounceInterpolator()); translateAnimation.setDuration(durationMillis); translateAnimation.setFillAfter(fillAfter);//this animation performed will persist when it is finished view.startAnimation(translateAnimation); }
From source file:Main.java
/** * move the background view(translate animation). * // w w w .j a va 2s . co m * @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 Animation getTranslationAnimation(boolean fromTheCenter, boolean toTheRight, int distance, int time) { Animation animation = null;//from w w w. ja v a2 s . c o m if (fromTheCenter && toTheRight) { animation = new TranslateAnimation(0, distance, 0, 0); } else if (fromTheCenter && !toTheRight) { animation = new TranslateAnimation(0, -distance, 0, 0); } else if (!fromTheCenter && toTheRight) { animation = new TranslateAnimation(distance, 0, 0, 0); } else if (!fromTheCenter && !toTheRight) { animation = new TranslateAnimation(-distance, 0, 0, 0); } animation.setDuration(time); animation.setFillAfter(true); return animation; }
From source file:Main.java
public static void expandOrCollapse(final View v, boolean expand) { TranslateAnimation anim;/*www . j a va2 s. c o 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 Animation slideIn(View view, int from) { view.setVisibility(View.VISIBLE); Animation anim;/*from w w w .j ava 2s . com*/ switch (from) { case DIRECTION_LEFT: anim = new TranslateAnimation(-view.getWidth(), 0, 0, 0); break; case DIRECTION_RIGHT: anim = new TranslateAnimation(view.getWidth(), 0, 0, 0); break; case DIRECTION_UP: anim = new TranslateAnimation(0, 0, -view.getHeight(), 0); break; case DIRECTION_DOWN: anim = new TranslateAnimation(0, 0, view.getHeight(), 0); break; default: throw new IllegalArgumentException(Integer.toString(from)); } anim.setDuration(500); view.startAnimation(anim); return anim; }
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. ja 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 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);//from www . j a va 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
/** * translate the view.// ww w . j av a 2 s .co m * * @param view view to be translated * @param fromXDelta Change in X coordinate to apply at the start of the * animation * @param toXDelta Change in X coordinate to apply at the end of the * animation * @param fromYDelta Change in Y coordinate to apply at the start of the * animation * @param toYDelta Change in Y coordinate to apply at the end of the * animation * @param cycles Repeats the animation for a specified number of cycles {@link CycleInterpolator}. * @param durationMillis Duration in milliseconds * @param isBanClick whether view can click in animation */ public static void translate(final View view, float fromXDelta, float toXDelta, float fromYDelta, float toYDelta, float cycles, long durationMillis, final boolean isBanClick) { TranslateAnimation translateAnimation = new TranslateAnimation(fromXDelta, toXDelta, fromYDelta, toYDelta); translateAnimation.setDuration(durationMillis); if (cycles > 0.0) { translateAnimation.setInterpolator(new CycleInterpolator(cycles)); } translateAnimation.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation animation) { if (isBanClick) { view.setClickable(false); } } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { if (isBanClick) { view.setClickable(true); } } }); view.startAnimation(translateAnimation); }