animate Height with ValueAnimator - Android Animation

Android examples for Animation:Animation Creation

Description

animate Height with ValueAnimator

Demo Code


//package com.java2s;

import android.animation.ValueAnimator;

import android.view.View;
import android.view.ViewGroup;

public class Main {
    public static void animateHeight(final View view, int from, int to,
            int duration) {
        boolean expanding = to > from;

        ValueAnimator anim = ValueAnimator.ofInt(from, to);
        anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override//from  ww w. ja v  a 2s . c o m
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                int val = (Integer) valueAnimator.getAnimatedValue();
                ViewGroup.LayoutParams layoutParams = view
                        .getLayoutParams();
                layoutParams.height = val;
                view.setLayoutParams(layoutParams);
            }
        });
        anim.setDuration(duration);
        anim.start();

    }
}

Related Tutorials