Skip to content

Instantly share code, notes, and snippets.

@boxme
Created March 12, 2015 02:48
Show Gist options
  • Save boxme/efc28cb3a567381aad6a to your computer and use it in GitHub Desktop.
Save boxme/efc28cb3a567381aad6a to your computer and use it in GitHub Desktop.
Switching between views with reveal and hide animations
private void setupView() {
mViewStateIndicator.setImageResource(mIsRevealed
? R.drawable.revealed
: R.drawable.not_revealed);
int hideTranslateY = -mToBeRevealedViewContainer.getHeight() / 4; // last 25% of animation
if (mIsRevealed && mToBeRevealedViewContainer.getTranslationY() == 0) {
// initial setup
mToBeRevealedViewContainer.setAlpha(0);
mToBeRevealedViewContainer.setTranslationY(hideTranslateY);
}
AnimatorSet set = new AnimatorSet();
set.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mSoonToBeHiddedViewContainer.setVisibility(mIsRevealed
? View.INVISIBLE : View.VISIBLE);
mToBeRevealedViewContainer.setVisibility(mIsRevealed
? View.VISIBLE : View.INVISIBLE);
}
@Override
public void onAnimationCancel(Animator animation) {
onAnimationEnd(animation);
}
});
if (mIsRevealed) {
mToBeRevealedViewContainer.setVisibility(View.VISIBLE);
AnimatorSet subSet = new AnimatorSet();
subSet.playTogether(
ObjectAnimator.ofFloat(mToBeRevealedViewContainer, View.ALPHA, 1)
.setDuration(EXPAND_ANIM_DURATION),
ObjectAnimator.ofFloat(mToBeRevealedViewContainer, View.TRANSLATION_Y, 0)
.setDuration(EXPAND_ANIM_DURATION));
set.playSequentially(
ObjectAnimator.ofFloat(mSoonToBeHiddedViewContainer, View.ALPHA, 0)
.setDuration(EXPAND_ANIM_DURATION),
subSet);
set.start();
} else {
mSoonToBeHiddedViewContainer.setVisibility(View.VISIBLE);
AnimatorSet subSet = new AnimatorSet();
subSet.playTogether(
ObjectAnimator.ofFloat(mToBeRevealedViewContainer, View.ALPHA, 0)
.setDuration(EXPAND_ANIM_DURATION),
ObjectAnimator.ofFloat(mToBeRevealedViewContainer, View.TRANSLATION_Y,
hideTranslateY)
.setDuration(EXPAND_ANIM_DURATION));
set.playSequentially(
subSet,
ObjectAnimator.ofFloat(mSoonToBeHiddedViewContainer, View.ALPHA, 1)
.setDuration(EXPAND_ANIM_DURATION));
set.start();
}
set.start();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment