animate Hide Show View - Android User Interface

Android examples for User Interface:View Hide Show

Description

animate Hide Show View

Demo Code


//package com.java2s;
import android.view.View;

import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;

import android.view.animation.Transformation;

public class Main {

    public static void animHideShowView(final View v, AnimationListener al,
            int measureHeight, final boolean show, int ainmTime) {

        if (measureHeight == 0) {
            measureHeight = v.getMeasuredHeight();
        }// w  w  w  .j  a  va2  s.c om
        final int heightMeasure = measureHeight;
        Animation anim = new Animation() {

            @Override
            protected void applyTransformation(float interpolatedTime,
                    Transformation t) {

                if (interpolatedTime == 1) {
                    v.setVisibility(show ? View.VISIBLE : View.GONE);
                } else {
                    int height;
                    if (show) {
                        height = (int) (heightMeasure * interpolatedTime);
                    } else {
                        height = heightMeasure
                                - (int) (heightMeasure * interpolatedTime);
                    }
                    v.getLayoutParams().height = height;
                    v.requestLayout();
                }
            }

            @Override
            public boolean willChangeBounds() {
                return true;
            }
        };

        if (al != null) {
            anim.setAnimationListener(al);
        }
        anim.setDuration(ainmTime);
        v.startAnimation(anim);
    }
}

Related Tutorials