Skip to content

Instantly share code, notes, and snippets.

@rafali
Last active February 26, 2021 13:05
Show Gist options
  • Star 68 You must be signed in to star a gist
  • Fork 15 You must be signed in to fork a gist
  • Save rafali/5146957 to your computer and use it in GitHub Desktop.
Save rafali/5146957 to your computer and use it in GitHub Desktop.
Resize animation on Android
public class ResizeAnimation extends Animation {
final int startWidth;
final int targetWidth;
View view;
public ResizeAnimation(View view, int targetWidth) {
this.view = view;
this.targetWidth = targetWidth;
startWidth = view.getWidth();
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
int newWidth = (int) (startWidth + (targetWidth - startWidth) * interpolatedTime);
view.getLayoutParams().width = newWidth;
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;
}
}
ResizeAnimation resizeAnimation = new ResizeAnimation(view, targetSize);
resizeAnimation.setDuration(600);
view.startAnimation(resizeAnimation);
@EmmanuelMess
Copy link

Isn't initialize() redundant here?

@devarc
Copy link

devarc commented Jan 23, 2019

Its not work when we call inside another view touch listener or click listener, there are any Idea.

@alaaalzibda
Copy link

It worked for me, Thanks

@whitescent
Copy link

so nice code, it can works for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment