Android View Collapse and Expand Animations

// To animate view slide outpublic void collapseView(View view) {
    HeightAnimation heightAnim = new HeightAnimation(view, view.getHeight(), 0);
    heightAnim.setDuration(500);
    view.startAnimation(heightAnim);
}

// To animate view slide inpublic void expandView(View view) {
    HeightAnimation heightAnim = new HeightAnimation(view, 0,
            (int) (51 * AppDisplayManager.getInstance().getDeviceDensity()));
    heightAnim.setDuration(200);
    view.startAnimation(heightAnim);
}

public class HeightAnimation extends Animation {
    protected final int originalHeight;
    protected final View view;
    protected float perValue;

    public HeightAnimation(View view, int fromHeight, int toHeight) {
        this.view = view;
        this.originalHeight = fromHeight;
        this.perValue = (toHeight - fromHeight);
    }

    @Override    protected void applyTransformation(float interpolatedTime, Transformation t) {
        view.getLayoutParams().height = (int) (originalHeight + perValue * interpolatedTime);
        view.requestLayout();
    }

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

Comments

Popular posts from this blog

Working with Android Hierarchy Viewer

Android: Standalone login with SQLiteOpenHelper