ImageView myImageView = (ImageView)findViewById(R.id.my_imageview); AnimationSet animSet = new AnimationSet(true); animSet.setInterpolator(new DecelerateInterpolator()); animSet.setFillAfter(true); animSet.setFillEnabled(true); final RotateAnimation animRotate = new RotateAnimation(0.0f, -90.0f, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f); animRotate.setDuration(1500); animRotate.setFillAfter(true); animSet.addAnimation(animRotate); myImageView.startAnimation(animSet);
private void moveViewToScreenCenter( final View view ){ DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics( dm ); int originalPos[] = new int[2]; view.getLocationOnScreen( originalPos ); int xDelta = (dm.widthPixels - view.getMeasuredWidth() - originalPos[0])/2; int yDelta = (dm.heightPixels - view.getMeasuredHeight() - originalPos[1])/2; AnimationSet animSet = new AnimationSet(true); animSet.setFillAfter(true); animSet.setDuration(1000); animSet.setInterpolator(new BounceInterpolator()); TranslateAnimation translate = new TranslateAnimation( 0, xDelta , 0, yDelta); animSet.addAnimation(translate); ScaleAnimation scale = new ScaleAnimation(1f, 2f, 1f, 2f, ScaleAnimation.RELATIVE_TO_PARENT, .5f, ScaleAnimation.RELATIVE_TO_PARENT, .5f); animSet.addAnimation(scale); view.startAnimation(animSet); }
set.setFillAfter(false); set.addAnimation(scaleAnimation); set.addAnimation(translateAnimationY);
public A fillAfter(boolean fillAfter) { animSet.setFillAfter(fillAfter); return this; }
public void animar(AnimationSet lista) { ImageView img = (ImageView) findViewById(R.id.img); // 2 segundos lista.setDuration(2000); // Manter o efeito no final da animação lista.setFillAfter(true); img.startAnimation(lista); // Inverte o flag para na próxima vez utilizar a animação inversa flag = !flag; }
ImageView myImageView = (ImageView)findViewById(R.id.my_imageview); AnimationSet animSet = new AnimationSet(true); animSet.setInterpolator(new DecelerateInterpolator()); animSet.setFillAfter(true); animSet.setFillEnabled(true); final RotateAnimation animRotate = new RotateAnimation(0.0f, -90.0f, RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f); animRotate.setDuration(1500); animRotate.setFillAfter(true); animSet.addAnimation(animRotate); myImageView.startAnimation(animSet);
private void animateUpIn(@NonNull final View contentView) { TranslateAnimation translate = new TranslateAnimation( Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 0f ); AlphaAnimation alpha = new AlphaAnimation(0, 1); AnimationSet set = new AnimationSet(true); set.addAnimation(translate); set.addAnimation(alpha); set.setInterpolator(new DecelerateInterpolator()); set.setDuration(200); set.setFillAfter(true); contentView.startAnimation(set); }
AnimationSet animation = new AnimationSet(true); animation.setFillAfter(true); TranslateAnimation translateAnimation = new TranslateAnimation(0, destX - srcX, 0, destY - srcY); translateAnimation.setInterpolator(new LinearInterpolator()); translateAnimation.setDuration((long) MGConstant.ANIMATE_DURATION); animation.addAnimation(translateAnimation); RotateAnimation rotateAnimation = new RotateAnimation(0, degrees, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotateAnimation.setInterpolator(new LinearInterpolator()); rotateAnimation.setDuration((long) MGConstant.ANIMATE_DURATION); rotateAnimation.setStartOffset((long) MGConstant.ANIMATE_DURATION); animation.addAnimation(rotateAnimation); startAnimation(animation);
TranslateAnimation translateAnim = new TranslateAnimation(fromX , toX , fromY , toY); ScaleAnimation scaleAnim = new ScaleAnimation(fromX , toX , fromY , toY); AnimationSet animSet = new AnimationSet(true); animSet.addAnimation(translateAnim); animSet.addAnimation(scaleAnim); animSet.setFillAfter(true); animSet.setDuration(...);
AnimationSet animSet = new AnimationSet(false); Animation AnimFirst = AnimationUtils.loadAnimation(act, R.anim.first); Animation rAnimSecond = AnimationUtils.loadAnimation(act, R.anim.second); animSet.addAnimation(AnimFirst); animSet.addAnimation(AnimSecond); animSet.setInterpolator(new AccelerateDecelerateInterpolator()); icon.clearAnimation(); animSet.setFillAfter(true); icon.startAnimation(animSet);
TranslateAnimation translateAnim = new TranslateAnimation(0, desX, 0, desY); ScaleAnimation scaleAnim = new ScaleAnimation(1, 0.2f, 1, 1Animation.RELATIVE_TO_SELF, 0.5f,Animation.RELATIVE_TO_SELF, 0.5f); AnimationSet set = new AnimationSet(false); set.addAnimation(translateAnim); set.addAnimation(scaleAnim); set.setFillEnabled(true); set.setFillAfter(true); set.setDuration(300); mView.startAnimation(set);
protected synchronized void animateNow() { View view = this.view.get(); if (view != null) { AnimationSet set = new AnimationSet(true); for (Animation animation : animations) if (animation != null) set.addAnimation(animation); set.setDuration(0); set.setFillAfter(true); view.setAnimation(set); set.start(); animations.clear(); } }
private void animateScaleIn() { if (mContentView == null) { return; } ScaleAnimation scaleAnimation = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); AlphaAnimation alpha = new AlphaAnimation(0, 1); AnimationSet set = new AnimationSet(true); set.addAnimation(scaleAnimation); set.addAnimation(alpha); set.setInterpolator(new DecelerateInterpolator()); set.setDuration(mAnimationDuration ); set.setFillAfter(true); mContentView.startAnimation(set); }
private Animation scaleSmallAnim(int duration) { AnimationSet animset = new AnimationSet(true); ScaleAnimation scaleAnim = new ScaleAnimation(1.0f, 0.0f, 1.0f, 0.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); AlphaAnimation alphaAnim = new AlphaAnimation(1.0f, 0.0f); animset.addAnimation(scaleAnim); animset.addAnimation(alphaAnim); animset.setDuration(duration); animset.setFillAfter(true); return animset; }
private Animation createLogoAnim() { final ScaleAnimation tvScaleAnim = new ScaleAnimation(1.0f, 1.3f, 1.0f, 1.3f , Animation.RELATIVE_TO_SELF, 0.5F, Animation.RELATIVE_TO_SELF, 0.5f); final TranslateAnimation tvTranslateAnim = new TranslateAnimation(0, 0, 0, -40); final AnimationSet tvAnimationSet = new AnimationSet(true); tvAnimationSet.addAnimation(tvScaleAnim); tvAnimationSet.addAnimation(tvTranslateAnim); tvAnimationSet.setDuration(3000); tvAnimationSet.setFillAfter(true); return tvAnimationSet; }
public Animation showAnimation() { AnimationSet set = new AnimationSet(true); Animation alphaAnimation = new AlphaAnimation(0.0f, 1.0f); Animation scaleAnimation = new ScaleAnimation(0.1f, 1f, 0.1f, 1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); set.setDuration(200); set.setInterpolator(new DecelerateInterpolator()); set.addAnimation(alphaAnimation); set.addAnimation(scaleAnimation); set.setFillAfter(false); return set; }
private Animation scaleBigAnim(int duration) { AnimationSet animset = new AnimationSet(true); ScaleAnimation scaleAnim = new ScaleAnimation(1.0f, 2.0f, 1.0f, 2.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); AlphaAnimation alphaAnim = new AlphaAnimation(1.0f, 0.0f); animset.addAnimation(scaleAnim); animset.addAnimation(alphaAnim); animset.setDuration(duration); animset.setFillAfter(true); return animset; }
private Animation addAnimation(int duration, Animation.AnimationListener animationListener) { AnimationSet animationSet = new AnimationSet(true); Animation alphaAnimation = new AlphaAnimation(1, 0); alphaAnimation.setFillAfter(true); animationSet.addAnimation(alphaAnimation); Animation largeAnimation = new ScaleAnimation(0f, 1.0f, 0f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); largeAnimation.setFillAfter(true); animationSet.addAnimation(largeAnimation); animationSet.setDuration(duration); animationSet.setAnimationListener(animationListener); animationSet.setFillAfter(true); return animationSet; }
Animation animRotate= AnimationUtils.loadAnimation(context, R.anim.image_rotate); Animation fade_in = AnimationUtils.loadAnimation(context, R.anim.fade_in); Animation fade_out = AnimationUtils.loadAnimation(context, R.anim.fade_out); AnimationSet s = new AnimationSet(false); s.addAnimation(fade_in); animRotate.setDuration((long) duration); animRotate.setStartOffset(fade_in.getDuration()); s.addAnimation(animRotate); fade_out.setStartOffset(fade_in.getDuration() + animRotate.getDuration()); s.addAnimation(fade_out); s.setFillAfter(true); image.startAnimation(s);
AnimationSet anim = new AnimationSet(false); final Animation ballInAnimation = AnimationUtils.loadAnimation(this, R.anim.ball_in); ballInAnimation.setFillBefore(true); final Animation ballShiftAnimation = AnimationUtils.loadAnimation(this,R.anim.ball_shift); ballShiftAnimation.setStartOffset(ballInAnimation.getDuration()); final Animation ballOutAnimation = AnimationUtils.loadAnimation(this,R.anim.ball_out); ballOutAnimation.setStartOffset(ballInAnimation.getDuration()+ ballShiftAnimation.getDuration()); anim.addAnimation(ballInAnimation); anim.addAnimation(ballShiftAnimation); anim.addAnimation(ballOutAnimation); anim.setFillAfter(true); ballImage.startAnimation(anim);