Skip to content

Instantly share code, notes, and snippets.

@William-ST
Created August 30, 2016 17:04
Show Gist options
  • Save William-ST/b105731a70370d158fcdfa77b659e2be to your computer and use it in GitHub Desktop.
Save William-ST/b105731a70370d158fcdfa77b659e2be to your computer and use it in GitHub Desktop.
package sulca.pe.expandenditem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Transformation;
/**
* Created by William_ST on 30/08/16.
*/
public class ResizeAnimation extends Animation {
private final String TAG = ResizeAnimation.class.getSimpleName();
private final int targetHeight;
private View view;
private int startHeight;
public ResizeAnimation(View view, int startHeight, int targetHeight) {
this.view = view;
this.targetHeight = targetHeight;
this.startHeight = startHeight;
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
if(startHeight < targetHeight){
int newHeight = (int) ((startHeight + targetHeight) * interpolatedTime);
view.getLayoutParams().height = newHeight;
view.requestLayout();
} else {
int newHeight = (int) ((startHeight + targetHeight) * (1-interpolatedTime));
view.getLayoutParams().height = newHeight;
view.requestLayout();
}
}
@Override
public void initialize(int width, int height, int parentWidth, int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
}
@Override
public boolean willChangeBounds() {
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment