Skip to content

Instantly share code, notes, and snippets.

@Ray33
Created April 10, 2017 09:13
Show Gist options
  • Save Ray33/f497f49b449e9946f0bd392cef47113c to your computer and use it in GitHub Desktop.
Save Ray33/f497f49b449e9946f0bd392cef47113c to your computer and use it in GitHub Desktop.
open and close animation
private void animateClosing() {
AnimatorSet animator = new AnimatorSet();
ObjectAnimator translation = ObjectAnimator.ofFloat(mSideTabs, "translationX", 0, sideTabsWidth);
ObjectAnimator fadeOut = ObjectAnimator.ofFloat(mSideTabs, "alpha", 1f, 0f);
animator.playTogether(translation, fadeOut);
animator.setDuration(300);
animator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
isAnimated = true;
}
@Override
public void onAnimationEnd(Animator animation) {
stopSelf();
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
animator.start();
}
private void animateX(final int startValue, final int endValue, final boolean isOpened) {
ValueAnimator anim = ValueAnimator.ofInt(startValue, endValue);
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
int val = (Integer) valueAnimator.getAnimatedValue();
WindowManager.LayoutParams params = (WindowManager.LayoutParams) mSideTabs.getLayoutParams();
params.x = val;
mWindowManager.updateViewLayout(mSideTabs, params);
}
});
anim.setDuration(500);
anim.setInterpolator(new AccelerateDecelerateInterpolator());
anim.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
isAnimated = true;
FloatingTabService.this.isOpened = isOpened;
}
@Override
public void onAnimationEnd(Animator animation) {
isAnimated = false;
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
anim.start();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment