1import android.animation.Animator;
2import android.animation.AnimatorListenerAdapter;
3import android.view.View;
4
5public final class AnimationUtils {
6
7 public static void slideDown(final View view) {
8 view.animate()
9 .translationY(view.getHeight())
10 .alpha(0.f)
11 .setListener(new AnimatorListenerAdapter() {
12 @Override
13 public void onAnimationEnd(Animator animation) {
14 // superfluous restoration
15 view.setVisibility(View.GONE);
16 view.setAlpha(1.f);
17 view.setTranslationY(0.f);
18 }
19 });
20 }
21
22 public static void slideUp(final View view) {
23 view.setVisibility(View.VISIBLE);
24 view.setAlpha(0.f);
25
26 if (view.getHeight() > 0) {
27 slideUpNow(view);
28 } else {
29 // wait till height is measured
30 view.post(new Runnable() {
31 @Override
32 public void run() {
33 slideUpNow(view);
34 }
35 });
36 }
37 }
38
39 private static void slideUpNow(final View view) {
40 view.setTranslationY(view.getHeight());
41 view.animate()
42 .translationY(0)
43 .alpha(1.f)
44 .setListener(new AnimatorListenerAdapter() {
45 @Override
46 public void onAnimationEnd(Animator animation) {
47 view.setVisibility(View.VISIBLE);
48 view.setAlpha(1.f);
49 }
50 });
51 }
52
53}