Skip to content

Instantly share code, notes, and snippets.

@zirouan
Created July 20, 2017 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zirouan/63f26db708980d504e079ba6afa02924 to your computer and use it in GitHub Desktop.
Save zirouan/63f26db708980d504e079ba6afa02924 to your computer and use it in GitHub Desktop.
public static void showHideUpDown(boolean status, final View view, long duration) {
if (status) {
view.setAlpha(1f);
view.setTranslationY(0f);
view.animate().alpha(0f)
.translationY(view.getHeight())
.setDuration(duration)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
view.setVisibility(View.GONE);
}
}).start();
} else {
view.setVisibility(View.VISIBLE);
view.setAlpha(0f);
view.setTranslationY(view.getHeight());
view.animate()
.alpha(1f)
.translationY(0f)
.setDuration(duration)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
view.setVisibility(View.VISIBLE);
}
})
.start();
}
}
public static void showHideUpDown(boolean status, final View view) {
if (status) {
view.setAlpha(1f);
view.setTranslationY(0f);
view.animate().alpha(0f)
.translationY(view.getHeight())
.setDuration(175L)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
view.setVisibility(View.GONE);
}
}).start();
} else {
view.setVisibility(View.VISIBLE);
view.setAlpha(0f);
view.setTranslationY(view.getHeight());
view.animate()
.alpha(1f)
.translationY(0f)
.setDuration(175L)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
view.setVisibility(View.VISIBLE);
}
})
.start();
}
}
public static void expand(final View view, int targetHeight) {
view.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
view.getLayoutParams().height = 0;
view.setVisibility(View.VISIBLE);
ValueAnimator valueAnimator = ValueAnimator.ofInt(0, targetHeight);
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
view.getLayoutParams().height = (int) animation.getAnimatedValue();
view.requestLayout();
}
});
valueAnimator.setInterpolator(new DecelerateInterpolator());
valueAnimator.setDuration((int) (targetHeight / view.getContext().getResources().getDisplayMetrics().density));
valueAnimator.start();
}
public static void collapse(final View view) {
int targetHeight = view.getHeight();
ValueAnimator valueAnimator = ValueAnimator.ofInt(targetHeight, 0);
valueAnimator.setInterpolator(new DecelerateInterpolator());
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
view.getLayoutParams().height = (int) animation.getAnimatedValue();
view.requestLayout();
}
});
valueAnimator.setInterpolator(new DecelerateInterpolator());
valueAnimator.setDuration((int) (targetHeight / view.getContext().getResources().getDisplayMetrics().density));
valueAnimator.start();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment