private int startHeight;
private int deltaHeight; // distance between start and end height
/**
* constructor, do not forget to use the setParams(int, int) method before
* starting the animation
* @param v
*/
public ResizeAnimation (View v) {
this.view = v;
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
view.getLayoutParams().height = (int) (startHeight + deltaHeight * interpolatedTime);
view.requestLayout();
}
/**
* set the starting and ending height for the resize animation
* starting height is usually the views current height, the end height is the height
* we want to reach after the animation is completed
* @param start height in pixels
* @param end height in pixels
*/
public void setHeightDifference(int start, int end) {
this.startHeight = start;
deltaHeight = end - startHeight;
}
/**
* set the starting and ending width for the resize animation
* starting width is usually the views current width, the end width is the width
* we want to reach after the animation is completed
* @param start height in pixels
* @param end height in pixels
*/
public void setHeightDifference(int start, int end) {
this.startWidth = start;
deltaWidth = end - startWidth;
}
/**
* set the duration for the hideshowanimation
*/
@Override
public void setDuration(long durationMillis) {
super.setDuration(durationMillis);
}
@Override
public boolean willChangeBounds() {
return true;
}
}
clickableLayout.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View V){
RelativeLayout v = (RelativeLayout) V;
// getting the layoutparams might differ in your application, it depends on the parent layout
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) v.getLayoutParams();
a.setDuration(500);
a.setParams(lp.height, newHeight); relativeLayout.startAnimation(a);
v.startAnimation(a)
}
}