Android examples for Animation:Collapse Animation
collapse a View to hide or show
//package com.java2s; import android.view.View; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.view.animation.Transformation; public class Main { public static void collapse(final View v, boolean hide, Animation.AnimationListener listener) { final int initialHeight = v.getMeasuredHeight(); collapseVertical(v, (int) (initialHeight / v.getContext() .getResources().getDisplayMetrics().density), hide, listener);/*from w w w .j ava2s .c om*/ } public static void collapseVertical(final View v, int duration, final boolean hide, Animation.AnimationListener listener) { final int initialHeight = v.getMeasuredHeight(); Animation a = new AlphaAnimation((float) 1.0, (float) 0.0) { @Override protected void applyTransformation(float interpolatedTime, Transformation t) { super.applyTransformation(interpolatedTime, t); if (interpolatedTime == 1 && hide) { v.setVisibility(View.INVISIBLE); } else { v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime); v.requestLayout(); } } @Override public boolean willChangeBounds() { return true; } }; if (listener != null) { a.setAnimationListener(listener); } a.setDuration(duration); v.startAnimation(a); } }