Skip to content

Instantly share code, notes, and snippets.

@yongjhih
Last active August 29, 2015 14:04
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 yongjhih/4b81bf0dc5eb9996c4ea to your computer and use it in GitHub Desktop.
Save yongjhih/4b81bf0dc5eb9996c4ea to your computer and use it in GitHub Desktop.
Android Animation Util
private static void pulse(View view) {
animateFromResource(view, R.anim.pulse_out_repeat);
}
private static void fadein(View view) {
animateFromResource(view, android.R.anim.fade_in);
}
private static void fadeout(View view) {
animateOutFromResource(view, android.R.anim.fade_out);
}
public static void animateFromResource(final View view, int animationId) {
animateInFromResource(view, animationId);
}
public static void animateInFromResource(final View view, int animationId) {
animateFromResource(view, animationId, false);
}
public static void animateOutFromResource(final View view, int animationId) {
animateFromResource(view, animationId, true);
}
public static void animateFromResource(final View view, int animationId, final boolean out) {
if (view == null) return;
final Animation animation = AnimationUtils.loadAnimation(view.getContext(), animationId);
final float alpha = view.getAlpha();
animation.setAnimationListener(new AnimationListener() {
@Override public void onAnimationStart(Animation animation) {}
@Override public void onAnimationRepeat(Animation animation) {}
@Override public void onAnimationEnd(Animation animation) {
if (out) {
view.setVisibility(View.GONE);
view.setAlpha(alpha);
}
}
});
if (!out) view.setVisibility(View.VISIBLE);
view.startAnimation(animation);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment