Created
November 18, 2014 16:34
-
-
Save michalfaber/e9659213afb26635ca76 to your computer and use it in GitHub Desktop.
Universal FadeIn FadeOut for Android
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
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) | |
private void fadeOut(final View view) { | |
int sdk = android.os.Build.VERSION.SDK_INT; | |
if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) { | |
AlphaAnimation alpha = new AlphaAnimation(1f, 0f); | |
alpha.setDuration(mShortAnimationDuration); | |
alpha.setFillAfter(true); | |
view.startAnimation(alpha); | |
} else { | |
view.animate() | |
.alpha(0f) | |
.setDuration(mShortAnimationDuration) | |
.setListener(new AnimatorListenerAdapter() { | |
@Override | |
public void onAnimationEnd(Animator animation) { | |
view.setVisibility(View.GONE); | |
} | |
}); | |
} | |
} | |
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) | |
private void fadeIn(View view) { | |
int sdk = android.os.Build.VERSION.SDK_INT; | |
if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) { | |
view.setVisibility(View.VISIBLE); | |
AlphaAnimation alpha = new AlphaAnimation(0f, 1f); | |
alpha.setDuration(mShortAnimationDuration); | |
alpha.setFillAfter(true); | |
view.startAnimation(alpha); | |
} else { | |
view.setAlpha(0f); | |
view.setVisibility(View.VISIBLE); | |
view.animate() | |
.alpha(1f) | |
.setDuration(mShortAnimationDuration) | |
.setListener(null); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment