Back to project page MultiWork.
The source code is released under:
Copyright (c) 2013, Torti Andr?s Fernando All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions a...
If you think the Android project MultiWork listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.tjerkw.slideexpandable.library; /* w w w .j ava2 s. c o m*/ import android.view.View; import android.view.animation.Animation; import android.view.animation.Transformation; import android.widget.LinearLayout; /** * Animation that either expands or collapses a view by sliding it down to make it visible. * Or by sliding it up so it will hide. It will look like it slides behind the view above. * * @auther tjerk * @date 6/9/12 4:58 PM */ public class ExpandCollapseAnimation extends Animation { private View mAnimatedView; private int mEndHeight; private int mType; public final static int COLLAPSE = 1; public final static int EXPAND = 0; private LinearLayout.LayoutParams mLayoutParams; /** * Initializes expand collapse animation, has two types, collapse (1) and expand (0). * @param view The view to animate * @param type The type of animation: 0 will expand from gone and 0 size to visible and layout size defined in xml. * 1 will collapse view and set to gone */ public ExpandCollapseAnimation(View view, int type) { mAnimatedView = view; mEndHeight = mAnimatedView.getMeasuredHeight(); mLayoutParams = ((LinearLayout.LayoutParams) view.getLayoutParams()); mType = type; if(mType == EXPAND) { mLayoutParams.bottomMargin = -mEndHeight; } else { mLayoutParams.bottomMargin = 0; } view.setVisibility(View.VISIBLE); } @Override protected void applyTransformation(float interpolatedTime, Transformation t) { super.applyTransformation(interpolatedTime, t); if (interpolatedTime < 1.0f) { if(mType == EXPAND) { mLayoutParams.bottomMargin = -mEndHeight + (int) (mEndHeight * interpolatedTime); } else { mLayoutParams.bottomMargin = - (int) (mEndHeight * interpolatedTime); } //Log.d("ExpandCollapseAnimation", "anim height " + mLayoutParams.bottomMargin); mAnimatedView.requestLayout(); } else { if(mType == EXPAND) { mLayoutParams.bottomMargin = 0; mAnimatedView.requestLayout(); } else { mLayoutParams.bottomMargin = -mEndHeight; mAnimatedView.setVisibility(View.GONE); mAnimatedView.requestLayout(); } } } }