Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

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

import android.view.animation.Animation;
import android.view.animation.DecelerateInterpolator;

import android.view.animation.Transformation;

public class Main {
    /**
     * Collapsing the view into wrapping their contents
     *
     * @param v the target view
     */
    public static void collapse(final View v, Animation.AnimationListener listener) {
        final int initialHeight = v.getMeasuredHeight();
        v.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        collapse(v, initialHeight, v.getMeasuredHeight(), 500, listener);
    }

    public static void collapse(final View v, final int initialHeight, final int targetHeight, int duration,
            Animation.AnimationListener listener) {
        final int diffHeight = initialHeight - targetHeight;
        Animation a = new Animation() {
            @Override
            protected void applyTransformation(float interpolatedTime, Transformation t) {
                v.getLayoutParams().height = initialHeight - (int) (diffHeight * interpolatedTime);
                v.requestLayout();
            }

            @Override
            public boolean willChangeBounds() {
                return true;
            }
        };
        a.setDuration(duration);
        a.setInterpolator(new DecelerateInterpolator(2));
        if (listener != null) {
            a.setAnimationListener(listener);
        }
        v.startAnimation(a);
    }
}