text Expand Animation - Android Animation

Android examples for Animation:Expand Animation

Description

text Expand Animation

Demo Code


//package com.java2s;

import android.view.View;

import android.view.animation.Animation;
import android.view.animation.Transformation;

public class Main {

    public static Animation textExpandAnimation(final View v,
            final boolean expand, int duration, int height) {
        final int initialHeight = height;

        if (expand) {
            v.getLayoutParams().height = 0;
        } else {/*from w w  w. j  a va  2 s.c  om*/
            v.getLayoutParams().height = initialHeight;
        }
        v.setVisibility(View.VISIBLE);

        Animation a = new Animation() {
            protected void applyTransformation(float interpolatedTime,
                    Transformation t) {
                int newHeight = 0;
                if (expand) {
                    newHeight = (int) (initialHeight * interpolatedTime);
                } else {
                    newHeight = (int) (initialHeight * (1 - interpolatedTime));
                }

                v.getLayoutParams().height = newHeight;
                v.requestLayout();
                if (interpolatedTime == 1 && !expand)
                    v.setVisibility(View.GONE);
            }

            @Override
            public boolean willChangeBounds() {
                return true;
            }
        };
        a.setDuration(duration);
        return a;
    }
}

Related Tutorials