public void toggle() {
TranslateAnimation anim = null;
isOpen = !isOpen;
if (isOpen) {
layoutRoot.setVisibility(View.VISIBLE);
anim = new TranslateAnimation(0.0f, 0.0f, layoutRoot.getHeight(), 0.0f);
} else {
anim = new TranslateAnimation(0.0f, 0.0f, 0.0f, layoutRoot.getHeight());
anim.setAnimationListener(collapseListener);
}
anim.setDuration(300);
anim.setInterpolator(new AccelerateInterpolator(1.0f));
layoutRoot.startAnimation(anim);
}
Animation.AnimationListener collapseListener = new Animation.AnimationListener() {
public void onAnimationEnd(Animation animation) {
layoutRoot.setVisibility(View.GONE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationStart(Animation animation) {
}
};