Java tutorial
//package com.java2s; //License from project: Open Source License import android.app.Activity; import android.view.View; import android.view.ViewGroup; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.AnticipateOvershootInterpolator; import android.view.animation.Interpolator; import android.view.animation.Transformation; public class Main { private static final int ANIMATION_DURATION = 300; public static void animateHeight(final View animated, final int from, final int to, final long duration, final Interpolator interpolator, final AnimationListener animationListener) { final Animation animation = new Animation() { @Override protected void applyTransformation(float interpolatedTime, Transformation t) { final int newHeight = (int) (from + (to - from) * interpolatedTime); setHeight(animated, newHeight); } @Override public boolean willChangeBounds() { return true; } }; animation.setDuration(duration); animation.setInterpolator(interpolator); if (animationListener != null) { animation.setAnimationListener(animationListener); } animated.startAnimation(animation); } public static void animateHeight(final View animated, final int from, final int to, final AnimationListener animationListener) { animateHeight(animated, from, to, ANIMATION_DURATION, new AnticipateOvershootInterpolator(0.4f), animationListener); } public static void setHeight(final View view, final int height) { if (view != null) { final ViewGroup.LayoutParams params = view.getLayoutParams(); // noinspection ConstantConditions params.height = height; view.setLayoutParams(params); } } public static void setHeight(final View root, final int viewId, final int height) { if (root != null) { setHeight(root.findViewById(viewId), height); } } public static void setHeight(final Activity root, final int viewId, final int height) { if (root != null) { setHeight(root.findViewById(viewId), height); } } }