Android Animation Util
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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