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 Animation createPositionAnimation(int fromY, int toY, float fromAlpha, float toAlpha, int duration) { TranslateAnimation translate = new TranslateAnimation(0, 0, fromY, toY); translate.setDuration(duration); AlphaAnimation alpha = new AlphaAnimation(fromAlpha, toAlpha); alpha.setDuration(duration); AnimationSet set = new AnimationSet(true); set.setInterpolator(new DecelerateInterpolator()); set.addAnimation(translate); set.addAnimation(alpha); return set; }
private Animation createBgImageInAnimation(int fromX, int toX, int transitionDuration, int alphaDuration) { TranslateAnimation translate = new TranslateAnimation(fromX, toX, 0, 0); translate.setDuration(transitionDuration); AlphaAnimation alpha = new AlphaAnimation(0F, 1F); alpha.setDuration(alphaDuration); AnimationSet set = new AnimationSet(true); set.setInterpolator(new DecelerateInterpolator()); set.addAnimation(translate); set.addAnimation(alpha); return set; }
public void toggle() { TranslateAnimation anim=null; AnimationSet set=new AnimationSet(true); isOpen=!isOpen; if (isOpen) { setVisibility(View.VISIBLE); anim=new TranslateAnimation(0.0f, 0.0f, getHeight(), 0.0f); } else { anim=new TranslateAnimation(0.0f, 0.0f, 0.0f, getHeight()); anim.setAnimationListener(collapseListener); set.addAnimation(fadeOut); } set.addAnimation(anim); set.setDuration(speed); set.setInterpolator(new AccelerateInterpolator(1.0f)); startAnimation(set); }
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); }
final float growTo = 1.2f; final long duration = 1200; ScaleAnimation grow = new ScaleAnimation(1, growTo, 1, growTo, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); grow.setDuration(duration / 2); ScaleAnimation shrink = new ScaleAnimation(growTo, 1, growTo, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); shrink.setDuration(duration / 2); shrink.setStartOffset(duration / 2); AnimationSet growAndShrink = new AnimationSet(true); growAndShrink.setInterpolator(new LinearInterpolator()); growAndShrink.addAnimation(grow); growAndShrink.addAnimation(shrink); thumbLike.startAnimation(growAndShrink);
private Animation getAnimationSet(boolean fromXML) { if (fromXML) { Animation animation = AnimationUtils.loadAnimation(this, R.anim.view_animation); return animation; } else { AnimationSet innerAnimationSet = new AnimationSet(true); innerAnimationSet.setInterpolator(new BounceInterpolator()); innerAnimationSet.setStartOffset(1000); innerAnimationSet.addAnimation(getScaleAnimation()); innerAnimationSet.addAnimation(getTranslateAnimation()); AnimationSet animationSet = new AnimationSet(true); animationSet.setInterpolator(new LinearInterpolator()); animationSet.addAnimation(getAlphaAnimation()); animationSet.addAnimation(getRotateAnimation()); animationSet.addAnimation(innerAnimationSet); return animationSet; } }
@Override public void run() { childLayout.setVisibility(View.VISIBLE); AnimationSet animationSet = new AnimationSet(true); animationSet.setDuration(duration); animationSet.setInterpolator(new AccelerateDecelerateInterpolator()); int pivotXType = Animation.RELATIVE_TO_SELF; animationSet.addAnimation(new TranslateAnimation(pivotXType, 0, pivotXType, 0, pivotXType, 1, pivotXType, 0)); animationSet.addAnimation(new AlphaAnimation(0, 1)); childLayout.startAnimation(animationSet); } }, delay);
public static Animation createBgImageInAnimation(int fromX, int toX, int transitionDuration) { TranslateAnimation translate = new TranslateAnimation(fromX, toX, 0, 0); translate.setDuration(transitionDuration); AnimationSet set = new AnimationSet(true); set.setInterpolator(new DecelerateInterpolator()); set.addAnimation(translate); return set; }
private void hideAnim() { mHideSet = new AnimationSet(true); mHideSet.setInterpolator(new LinearInterpolator()); AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f); TranslateAnimation hiddenAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f); mHideSet.addAnimation(alphaAnimation); mHideSet.addAnimation(hiddenAction); mHideSet.setDuration(300); } }
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);
@Override public void run() { childLayout.setVisibility(View.VISIBLE); AnimationSet animationSet = new AnimationSet(true); animationSet.setDuration(duration); animationSet.setInterpolator(new OvershootInterpolator(0.8f)); int pivotXType = Animation.RELATIVE_TO_SELF; animationSet.addAnimation(new TranslateAnimation(pivotXType, -1, pivotXType, 0, pivotXType, 0, pivotXType, 0)); animationSet.addAnimation(new AlphaAnimation(0, 1)); childLayout.startAnimation(animationSet); } }, delay);
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); }
View viewFrom = findViewById(R.id.viewA); View viewTo = findViewById(R.id.viewB); // Getting delta from center int delta = (viewTo.getLeft()+Math.round(viewTo.getWidth()*viewTo.getScaleX()))-(viewFrom.getLeft()+Math.round(viewFrom.getWidth()+viewFrom.getScaleX())); float ratio = viewTo.getScaleX() / viewFrom.getScaleX(); Animation anim = new ScaleAnimation(1.f, ratio, 1.f, ratio, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); AnimationSet animSet = new AnimationSet(true); animSet.setInterpolator(new DecelerateInterpolator()); animSet.addAnimation(anim); anim = new TranslateAnimation(0, delta, 0, 0); animSet.addAnimation(anim); animSet.setDuration(500); viewFrom.startAnimation(animSet);
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);
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); return set; }
@Override public Animation hideAnimation() { AnimationSet set = new AnimationSet(true); Animation alphaAnimation = new AlphaAnimation(1.0f, 0.0f); Animation scaleAnimation = new ScaleAnimation(1.0f, 0.1f, 1.0f, 0.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); return set; } }
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); }
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; }
AnimationSet as = new AnimationSet(true); as.setFillEnabled(true); as.setInterpolator(new BounceInterpolator()); as.addAnimation(firstAnim); as.addAnimation(secondAnim); as.setDuration(1000); imageView.startAnimation(as);