Java Code Examples for android.view.animation.AnimationSet.addAnimation()

The following are Jave code examples for showing how to use addAnimation() of the android.view.animation.AnimationSet class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: mapbox-navigation-android   File: InstructionView.java   Source Code and License Vote up 6 votes
/**
 * Initializes all animations needed to show / hide views.
 */
private void initAnimations() {
  Context context = getContext();
  rerouteSlideDownTop = AnimationUtils.loadAnimation(context, R.anim.slide_down_top);
  rerouteSlideUpTop = AnimationUtils.loadAnimation(context, R.anim.slide_up_top);

  Animation fadeIn = new AlphaAnimation(0, 1);
  fadeIn.setInterpolator(new DecelerateInterpolator());
  fadeIn.setDuration(300);

  Animation fadeOut = new AlphaAnimation(1, 0);
  fadeOut.setInterpolator(new AccelerateInterpolator());
  fadeOut.setStartOffset(1000);
  fadeOut.setDuration(1000);

  fadeInSlowOut = new AnimationSet(false);
  fadeInSlowOut.addAnimation(fadeIn);
  fadeInSlowOut.addAnimation(fadeOut);
}
 
Example 2
Project: FLFloatingButton   File: RayLayout.java   Source Code and License Vote up 6 votes
private static Animation createShrinkAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta,
		long startOffset, long duration, Interpolator interpolator) {
	AnimationSet animationSet = new AnimationSet(false);
	animationSet.setFillAfter(true);

	final long preDuration = duration / 2;
	Animation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f,
			Animation.RELATIVE_TO_SELF, 0.5f);
	rotateAnimation.setStartOffset(startOffset);
	rotateAnimation.setDuration(preDuration);
	rotateAnimation.setInterpolator(new LinearInterpolator());
	rotateAnimation.setFillAfter(true);

	animationSet.addAnimation(rotateAnimation);

	Animation translateAnimation = new RotateAndTranslateAnimation(0, toXDelta, 0, toYDelta, 360, 720);
	translateAnimation.setStartOffset(startOffset + preDuration);
	translateAnimation.setDuration(duration - preDuration);
	translateAnimation.setInterpolator(interpolator);
	translateAnimation.setFillAfter(true);

	animationSet.addAnimation(translateAnimation);

	return animationSet;
}
 
Example 3
Project: UiLib   File: ArcLayout.java   Source Code and License Vote up 6 votes
private static Animation createShrinkAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta,
                                               long startOffset, long duration, Interpolator interpolator) {
    AnimationSet animationSet = new AnimationSet(false);
    animationSet.setFillAfter(true);

    final long preDuration = duration / 2;
    Animation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f,
            Animation.RELATIVE_TO_SELF, 0.5f);
    rotateAnimation.setStartOffset(startOffset);
    rotateAnimation.setDuration(preDuration);
    rotateAnimation.setInterpolator(new LinearInterpolator());
    rotateAnimation.setFillAfter(true);

    animationSet.addAnimation(rotateAnimation);

    Animation translateAnimation = new RotateAndTranslateAnimation(0, toXDelta, 0, toYDelta, 360, 720);
    translateAnimation.setStartOffset(startOffset + preDuration);
    translateAnimation.setDuration(duration - preDuration);
    translateAnimation.setInterpolator(interpolator);
    translateAnimation.setFillAfter(true);

    animationSet.addAnimation(translateAnimation);

    return animationSet;
}
 
Example 4
Project: FLFloatingButton   File: ArcLayout.java   Source Code and License Vote up 6 votes
private static Animation createShrinkAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta,
        long startOffset, long duration, Interpolator interpolator) {
    AnimationSet animationSet = new AnimationSet(false);
    animationSet.setFillAfter(true);

    final long preDuration = duration / 2;
    Animation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f,
            Animation.RELATIVE_TO_SELF, 0.5f);
    rotateAnimation.setStartOffset(startOffset);
    rotateAnimation.setDuration(preDuration);
    rotateAnimation.setInterpolator(new LinearInterpolator());
    rotateAnimation.setFillAfter(true);

    animationSet.addAnimation(rotateAnimation);

    Animation translateAnimation = new RotateAndTranslateAnimation(0, toXDelta, 0, toYDelta, 360, 720);
    translateAnimation.setStartOffset(startOffset + preDuration);
    translateAnimation.setDuration(duration - preDuration);
    translateAnimation.setInterpolator(interpolator);
    translateAnimation.setFillAfter(true);

    animationSet.addAnimation(translateAnimation);

    return animationSet;
}
 
Example 5
Project: buildAPKsSamples   File: ListViewItemAnimations.java   Source Code and License Vote up 6 votes
/**
 * Sets the horizontal position and translucency of the view being swiped.
 */
@SuppressLint("NewApi")
private void setSwipePosition(View view, float deltaX) {
    float fraction = Math.abs(deltaX) / view.getWidth();
    if (isRuntimePostGingerbread()) {
        view.setTranslationX(deltaX);
        view.setAlpha(1 - fraction);
    } else {
        // Hello, Gingerbread!
        TranslateAnimation swipeAnim = new TranslateAnimation(deltaX, deltaX, 0, 0);
        mCurrentX = deltaX;
        mCurrentAlpha = (1 - fraction);
        AlphaAnimation alphaAnim = new AlphaAnimation(mCurrentAlpha, mCurrentAlpha);
        AnimationSet set = new AnimationSet(true);
        set.addAnimation(swipeAnim);
        set.addAnimation(alphaAnim);
        set.setFillAfter(true);
        set.setFillEnabled(true);
        view.startAnimation(set);
    }
}
 
Example 6
Project: letv   File: FragmentManagerImpl.java   Source Code and License Vote up 5 votes
static Animation makeOpenCloseAnimation(Context context, float startScale, float endScale, float startAlpha, float endAlpha) {
    AnimationSet set = new AnimationSet(false);
    ScaleAnimation scale = new ScaleAnimation(startScale, endScale, startScale, endScale, 1, 0.5f, 1, 0.5f);
    scale.setInterpolator(DECELERATE_QUINT);
    scale.setDuration(220);
    set.addAnimation(scale);
    AlphaAnimation alpha = new AlphaAnimation(startAlpha, endAlpha);
    alpha.setInterpolator(DECELERATE_CUBIC);
    alpha.setDuration(220);
    set.addAnimation(alpha);
    return set;
}
 
Example 7
Project: UiLib   File: RayMenu.java   Source Code and License Vote up 5 votes
private static Animation createItemDisapperAnimation(final long duration, final boolean isClicked) {
	AnimationSet animationSet = new AnimationSet(true);
	animationSet.addAnimation(new ScaleAnimation(1.0f, isClicked ? 2.0f : 0.0f, 1.0f, isClicked ? 2.0f : 0.0f,
			Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f));
	animationSet.addAnimation(new AlphaAnimation(1.0f, 0.0f));

	animationSet.setDuration(duration);
	animationSet.setInterpolator(new DecelerateInterpolator());
	animationSet.setFillAfter(true);

	return animationSet;
}
 
Example 8
Project: BottomMenu   File: BottomMenu.java   Source Code and License Vote up 5 votes
private Animation scaleSmallAnim(int duration, final View child) {

        AnimationSet animationSet = 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(1f, 0.0f);
        alphaAnim.setFillAfter(true);
        animationSet.addAnimation(scaleAnim);
        animationSet.addAnimation(alphaAnim);
        animationSet.setDuration(duration);

        return animationSet;

    }
 
Example 9
Project: Cable-Android   File: MicrophoneRecorderView.java   Source Code and License Vote up 5 votes
public void display(float x) {
  this.startPositionX = x;
  this.lastPositionX  = x;

  recordButtonFab.setVisibility(View.VISIBLE);

  float translation = ViewCompat.getLayoutDirection(recordButtonFab) ==
      ViewCompat.LAYOUT_DIRECTION_LTR ? -.25f : .25f;

  AnimationSet animation = new AnimationSet(true);
  animation.addAnimation(new TranslateAnimation(Animation.RELATIVE_TO_SELF, translation,
                                                Animation.RELATIVE_TO_SELF, translation,
                                                Animation.RELATIVE_TO_SELF, -.25f,
                                                Animation.RELATIVE_TO_SELF, -.25f));

  animation.addAnimation(new ScaleAnimation(.5f, 1f, .5f, 1f,
                                            Animation.RELATIVE_TO_SELF, .5f,
                                            Animation.RELATIVE_TO_SELF, .5f));

  animation.setFillBefore(true);
  animation.setFillAfter(true);
  animation.setDuration(ANIMATION_DURATION);
  animation.setInterpolator(new OvershootInterpolator());

  recordButtonFab.startAnimation(animation);
}
 
Example 10
Project: AnnularMenuView   File: AnnularMenu.java   Source Code and License Vote up 5 votes
/**
 * item变大的动画
 *
 * @return
 */
private Animation scaleBigAnimation(int duration) {
    AnimationSet animationSet = new AnimationSet(true);
    ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 2.5f, 1.0f, 2.5f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5F);
    AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f);
    animationSet.addAnimation(scaleAnimation);
    animationSet.addAnimation(alphaAnimation);
    animationSet.setDuration(duration);
    animationSet.setFillAfter(true);
    return animationSet;
}
 
Example 11
Project: SDCardCleaner   File: MainActivity.java   Source Code and License Vote up 5 votes
private AnimationSet createQuitAnimation(View _view, long _offSet) {
    AnimationSet _set = new AnimationSet(true);

    _set.addAnimation(new AlphaAnimation(1, 0));
    _set.addAnimation(new ScaleAnimation(1, 2, 1, 2));
    _set.addAnimation(new TranslateAnimation(0, -_view.getWidth() / 2, 0, -_view.getHeight() / 2));

    _set.setDuration(150);
    _set.setStartOffset(_offSet);
    _set.setFillAfter(true);
    return _set;
}
 
Example 12
Project: ExpandButton   File: ExpandButtonLayout.java   Source Code and License Vote up 5 votes
public void close() {

        AnimationSet animationSet = new AnimationSet(true);
        animationSet.setDuration(duration);
        animationSet.setAnimationListener(this);
        animationSet.setFillAfter(true);

        RotateAnimation rotateAnimation = new RotateAnimation(360, 270,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        animationSet.addAnimation(rotateAnimation);
        Animation scaleAnimation = new ScaleAnimation(1f, 1.25f, 1f, 1.25f,
                ScaleAnimation.RELATIVE_TO_SELF, 0.5f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
        animationSet.addAnimation(scaleAnimation);
        imageView.startAnimation(animationSet);
        AnimatorSet animatorSet = new AnimatorSet();
        ObjectAnimator animator1 = ObjectAnimator.ofInt(mLinearLayout, "width", mLinearLayoutWidth, 0);
        ObjectAnimator animator2 = ObjectAnimator.ofInt(mLinearLayout, "paddingLeft", savePaddingLeft, 0);
        ObjectAnimator animator3 = ObjectAnimator.ofInt(mLinearLayout, "paddingRight", savePaddingRight, 0);
        ObjectAnimator animator4 = ObjectAnimator.ofInt(mLinearLayout, "marginLeft", saveMarginLeft, 0);
        ObjectAnimator animator5 = ObjectAnimator.ofInt(mLinearLayout, "marginRight", saveMarginRight, 0);
        animatorSet.playTogether(animator1, animator2, animator3, animator4, animator5);
        animatorSet.setDuration(duration).start();

    }
 
Example 13
Project: AnimationsDemo   File: LabelView.java   Source Code and License Vote up 5 votes
public void wave() {
    AnimationSet as = new AnimationSet(true);
    ScaleAnimation sa = new ScaleAnimation(1f, 1.5f, 1f, 1.5f, ScaleAnimation.RELATIVE_TO_SELF,
            0.5f, ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
    sa.setDuration(ANIMATIONEACHOFFSET * 3);
    sa.setRepeatCount(10);// 设置循环
    AlphaAnimation aniAlp = new AlphaAnimation(1, 0.1f);
    aniAlp.setRepeatCount(10);// 设置循环
    as.setDuration(ANIMATIONEACHOFFSET * 3);
    as.addAnimation(sa);
    as.addAnimation(aniAlp);
    labelIcon.startAnimation(as);
}
 
Example 14
Project: Bigbang   File: ArcMenu.java   Source Code and License Vote up 5 votes
private static Animation createItemDisapperAnimation(final long duration, final boolean isClicked) {
    AnimationSet animationSet = new AnimationSet(true);
    animationSet.addAnimation(new ScaleAnimation(1.0f, isClicked ? 2.0f : 0.0f, 1.0f, isClicked ? 2.0f : 0.0f,
            Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f));
    animationSet.addAnimation(new AlphaAnimation(1.0f, 0.0f));

    animationSet.setDuration(duration);
    animationSet.setInterpolator(new DecelerateInterpolator());
    animationSet.setFillAfter(true);

    return animationSet;
}
 
Example 15
Project: RecyclerViewAnimation   File: MyLayoutAnimationHelper.java   Source Code and License Vote up 5 votes
/**
 * 放大动画
 *
 * @return
 */
public static AnimationSet getAnimationSetScaleBig() {
    AnimationSet animationSet = new AnimationSet(true);

    ScaleAnimation scaleAnimation = new ScaleAnimation(0.1f, 1.0f, 0.1f, 1.0f, RELATIVE_TO_SELF, 0.5f, RELATIVE_TO_SELF, 0.5f);
    scaleAnimation.setInterpolator(new DecelerateInterpolator());
    scaleAnimation.setDuration(400);


    animationSet.addAnimation(scaleAnimation);
    animationSet.setDuration(400);

    return animationSet;
}
 
Example 16
Project: TaipeiTechRefined   File: BaseFragment.java   Source Code and License Vote up 5 votes
@Override
public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
    Animation animation;
    if (enter) {
        animation = AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_in);
        animation.setAnimationListener(mAnimationListener);
    } else {
        animation = AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_out);
    }
    AnimationSet animationSet = new AnimationSet(false);
    animationSet.addAnimation(animation);
    return animationSet;
}
 
Example 17
Project: AnnularMenuView   File: AnnularMenu.java   Source Code and License Vote up 5 votes
private Animation scaleSmallAnimation(int duration) {
    AnimationSet animationSet = new AnimationSet(true);
    ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 0.0f, 1.0f, 0.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5F);
    AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f);
    animationSet.addAnimation(scaleAnimation);
    animationSet.addAnimation(alphaAnimation);
    animationSet.setDuration(duration);
    animationSet.setFillAfter(true);
    return animationSet;
}
 
Example 18
Project: Hotspot-master-devp   File: AnimationUtil.java   Source Code and License Vote up 4 votes
/**
 * 缩放+旋转动画出来
 * @param view  动画作用的视图
 * @param durationMillis    动画持续的时间
 * @param delayMillis     经过多少毫秒播放动画
 */
public static void scaleRotateOut(View view, long durationMillis, long delayMillis) {
	ScaleAnimation animation1 = new ScaleAnimation(1, 0, 1, 0, rela1, 0.5f, rela1, 0.5f);
	RotateAnimation animation2 = new RotateAnimation(0, 360, rela1, 0.5f, rela1, 0.5f);
	AnimationSet animation = new AnimationSet(false);
	animation.addAnimation(animation1);
	animation.addAnimation(animation2);
	baseOut(view, animation, durationMillis, delayMillis);
}
 
Example 19
Project: Marquee   File: MarqueeView.java   Source Code and License Vote up 4 votes
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    this.mContext = context;
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.MarqueeViewUp, defStyleAttr, 0);

    isSetAlphaAnim = ta.getBoolean(R.styleable.MarqueeViewUp_isSetAlphaAnim, isSetAlphaAnim);
    interval = ta.getInteger(R.styleable.MarqueeViewUp_interval, interval);
    animDuration = ta.getInteger(R.styleable.MarqueeViewUp_animDuration, animDuration);


    setFlipInterval(interval);

    //淡入淡出动画
    AlphaAnimation animationIn = new AlphaAnimation(0, 1);//淡入 从透明到不透明
    animationIn.setDuration(animDuration);//设置动画持续时间

    AlphaAnimation animationOut = new AlphaAnimation(1, 0);//淡出 从不透明到透明
    animationOut.setDuration(animDuration);//设置动画持续时间

    //平移动画
    TranslateAnimation translateAnimationIn = new TranslateAnimation(
            Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, 0.0f,
            Animation.RELATIVE_TO_SELF, 1.0f,
            Animation.RELATIVE_TO_SELF, 0.0f);//向上移动出现

    TranslateAnimation translateAnimationOut = 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); //向上移动消失
    translateAnimationIn.setDuration(animDuration);
    translateAnimationOut.setDuration(animDuration);

    // 动画集-- 进入动画
    AnimationSet animationInSet = new AnimationSet(false);
    animationInSet.addAnimation(translateAnimationIn);


    // 动画集-- 退出动画
    AnimationSet animationOutSet = new AnimationSet(false);
    animationOutSet.addAnimation(translateAnimationOut);

    if (isSetAlphaAnim) {
        //设置淡入淡出动画
        animationInSet.addAnimation(animationIn);
        animationOutSet.addAnimation(animationOut);
    }

    setInAnimation(animationInSet);
    setOutAnimation(animationOutSet);
}
 
Example 20
Project: PeSanKita-android   File: AttachmentTypeSelector.java   Source Code and License Vote up 4 votes
private void animateButtonIn(View button, int delay) {
  AnimationSet animation = new AnimationSet(true);
  Animation scale = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f,
                                       Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.0f);

  animation.addAnimation(scale);
  animation.setInterpolator(new OvershootInterpolator(1));
  animation.setDuration(ANIMATION_DURATION);
  animation.setStartOffset(delay);
  button.startAnimation(animation);
}