private void scrollUp() { for(int i = 0; i < getChildCount(); i++) { final View child = getChildAt(i); final int index = i; final int newleft = child.getLeft() + mOffsetBetweenItems; final int newTop = child.getTop() - mOffsetBetweenItems; TranslateAnimation scrollUp = new TranslateAnimation(0, mOffsetBetweenItems, 0, -mOffsetBetweenItems); scrollUp.setDuration(1500); scrollUp.setFillEnabled(true); scrollUp.setAnimationListener( new AnimationListener() { @Override public void onAnimationStart(Animation animation) {} @Override public void onAnimationRepeat(Animation animation) {} @Override public void onAnimationEnd(Animation animation) { child.layout(newleft, newTop, newleft + child.getMeasuredWidth(), newTop + child.getMeasuredHeight() ); } } ); child.startAnimation(scrollUp); } }
TranslateAnimation slideRight = new TranslateAnimation(0,newleft,0,0); slideRight.setDuration(500); slideRight.setFillEnabled(true); slideRight.setAnimationListener(AL); topLayout.startAnimation(slideRight); TranslateAnimation slideLeft = new TranslateAnimation(newleft,oldLeft,0,0); slideLeft.setDuration(500); slideLeft.setFillEnabled(true); slideLeft.setAnimationListener(AL); topLayout.startAnimation(slideLeft);
public static Animation getAnimation(long duration, float fromX, float toX, float fromY, float toY){ TranslateAnimation tAnimation = new TranslateAnimation(fromX,toX,fromY,toY); tAnimation.setDuration(duration); tAnimation.setFillEnabled(true); return tAnimation; }
ImageView viewToSlide = (ImageView) findViewById(R.id.your_image_view); TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0.80f, Animation.RELATIVE_TO_PARENT, 0, Animation.RELATIVE_TO_PARENT, 0); animation.setDuration(5000); animation.setFillEnabled(true); animation.setFillAfter(true); viewToSlide.startAnimation(animation);
TranslateAnimation translateAnimation = new TranslateAnimation(0, 50, 0, 0); int animationTime = 200; translateAnimation.setDuration(animationTime); translateAnimation.setFillEnabled(true); translateAnimation.setFillAfter(true); yourView.startAnimation(translateAnimation); yourView.setVisibility(View.VISIBLE);
TranslateAnimation anim = new TranslateAnimation(originalX, xValue, originalY, yValue); anim.setFillAfter(true); anim.setFillEnabled(true); anim.setDuration(ANIM_DURATION); myView.startAnimation(anim);
TranslateAnimation anim = new TranslateAnimation(xValue, originalX, yValue, originalY); anim.setFillAfter(true); anim.setFillEnabled(true); anim.setDuration(ANIM_DURATION); myView.startAnimation(anim);
TranslateAnimation tweenAnim = new TranslateAnimation(-1 * XStep, -1 * YStep , 0, 0); tweenAnim.setDuration(number_of_steps * 750); tweenAnim.setFillAfter(true); tweenAnim.setFillEnabled(true); tweenAnim.setInterpolator(new LinearInterpolator()); //layout positioning lp.leftMargin += XStep; lp.bottomMargin += YStep; imageView.setLayoutParams(lp); Log.v(TAG, "leftMargin=" + lp.leftMargin); Log.v(TAG, "bottomMargin=" + lp.bottomMargin); imageView.startAnimation(tweenAnim);
public void moveRight() { TranslateAnimation mMoveRight = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 300, Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF); mMoveRight.setDuration(6000); mMoveRight.setFillEnabled(true); mMoveRight.setFillAfter(true); this.startAnimation(mMoveRight); } ... public void moveDown() { TranslateAnimation mMoveDown = new TranslateAnimation(Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF, 50); mMoveDown.setDuration(6000); mMoveDown.setFillEnabled(true); mMoveDown.setFillAfter(true); this.startAnimation(mMoveDown); }
protected final void translateChild(View v, Point prev, Point now) { TranslateAnimation translate = new TranslateAnimation(Animation.ABSOLUTE, -now.x + prev.x, Animation.ABSOLUTE, 0, Animation.ABSOLUTE, -now.y + prev.y, Animation.ABSOLUTE, 0); translate.setInterpolator(new AccelerateInterpolator(4f)); translate.setDuration(350); translate.setFillEnabled(false); translate.setFillAfter(false); v.clearAnimation(); v.startAnimation(translate); }
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); 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); } }
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB_MR1) { ((RelativeLayout) findViewById(R.id.front_frame)).animate() .translationX(-1 * mScreenWidth); } else { TranslateAnimation slideOut = new TranslateAnimation(0, -1 * mScreenWidth, 0, 0); slideOut.setDuration(getResources().getInteger( R.integer.animation_transistion_length_short)); slideOut.setFillEnabled(true); slideOut.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation animation) {} @Override public void onAnimationRepeat(Animation animation) {} @Override public void onAnimationEnd(Animation animation) { RelativeLayout mView = (RelativeLayout) findViewById(R.id.front_frame); int[] pos = { mView.getLeft() - mScreenWidth, mView.getTop(), mView.getRight(), mView.getBottom() }; mView.layout(pos[0], pos[1], pos[2], pos[3]); } }); ((RelativeLayout) findViewById(R.id.front_frame)) .startAnimation(slideOut); }
TranslateAnimation moveAnim = new TranslateAnimation(-25, 25, -25, 25); moveAnim.setInterpolator(new AccelerateInterpolator()); moveAnim.setDuration(600); moveAnim.setFillEnabled(true); moveAnim.setFillAfter(true); moveAnim.setRepeatMode(AnimationSet.REVERSE); moveAnim.setRepeatCount(1); yourImageView.startAnimation(moveAnim);
ImageView imageView=(ImageView)findViewById(R.id.dot_image); int x=imageView.getRight()-imageView.getLeft(); int y=imageView.getBottom()-imageView.getTop(); TranslateAnimation translate = new TranslateAnimation( Animation.ABSOLUTE,x, Animation.ABSOLUTE, x, Animation.ABSOLUTE,y, Animation.ABSOLUTE,yPosition); translate.setDuration(150); translate.setFillEnabled(true); translate.setFillAfter(true); imageView.startAnimation(translate);
private void showIcons() { TranslateAnimation show = new TranslateAnimation( 0, 0, 0, -iconContainer.getMeasuredHeight()); show.setFillEnabled(true); show.setFillAfter(true); show.setDuration(200); iconContainer.clearAnimation(); iconContainer.startAnimation(show); }
private void hideIcons() { TranslateAnimation hide = new TranslateAnimation( 0, 0, -iconContainer.getMeasuredHeight(), 0); hide.setFillEnabled(true); hide.setFillAfter(true); hide.setDuration(200); iconContainer.clearAnimation(); iconContainer.startAnimation(hide); }
private void showWidget() { TranslateAnimation show = new TranslateAnimation( 0, 0, 0, widgetContainer.getMeasuredHeight()); show.setFillEnabled(true); show.setFillAfter(true); show.setDuration(200); widgetContainer.clearAnimation(); widgetContainer.startAnimation(show); }
private void hideWidget() { TranslateAnimation hide = new TranslateAnimation( 0, 0, widgetContainer.getMeasuredHeight(), 0); hide.setFillEnabled(true); hide.setFillAfter(true); hide.setDuration(200); widgetContainer.clearAnimation(); widgetContainer.startAnimation(hide); }
/** * Moves a card to a new destination. FillEnabled is necessary, or else flickering will occur. * The location is updated when the animation finishes, which happens in the onAnimationEnd() * method of the custom image view. * * @param card The card to move * @param pX X-coordinate of the destination * @param pY Y-coordinate of the destination */ public void moveCard(final Card card, final float pX, final float pY) { final CustomImageView view = card.view; int distance = (int) Math.sqrt(Math.pow(pX - view.getX(), 2) + Math.pow(pY - view.getY(), 2)); TranslateAnimation animation = new TranslateAnimation(0, pX - view.getX(), 0, pY - view.getY()); //there were some reports about an exception here, so simply set duration with a fixed value //if the exception occurs try { animation.setDuration((long) (distance * 100 / Card.width / speedFactor)); } catch (ArithmeticException e) { animation.setDuration(100); Log.e("Animate moveCard()", e.toString()); } animation.setFillEnabled(true); view.setDestination(pX, pY); view.startAnimation(animation); }
/** * Same as moveCard, but without the user specified speed factor. Used for the win animation. * * @param card The card to move * @param pX X-coordinate of the destination * @param pY Y-coordinate of the destination */ public void moveCardSlow(final Card card, final float pX, final float pY) { final CustomImageView view = card.view; if (card.isInvisible()){ return; } int distance = (int) Math.sqrt(Math.pow(pX - view.getX(), 2) + Math.pow(pY - view.getY(), 2)); TranslateAnimation animation = new TranslateAnimation(0, pX - view.getX(), 0, pY - view.getY()); try { animation.setDuration((long) (distance * 100 / Card.width)); } catch (ArithmeticException e) { animation.setDuration(200); Log.e("Animate moveCard()", e.toString()); } animation.setFillEnabled(true); view.setDestination(pX, pY); view.startAnimation(animation); }