Skip to content

Instantly share code, notes, and snippets.

@tprochazka
Created May 10, 2012 19:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tprochazka/2655404 to your computer and use it in GitHub Desktop.
Save tprochazka/2655404 to your computer and use it in GitHub Desktop.
How to animate width of any View
ValueAnimator.ofObject(new WidthEvaluator(view), 50, 500).setDuration(400).start();
import android.animation.IntEvaluator;
import android.view.View;
import android.view.ViewGroup;
public final class WidthEvaluator extends IntEvaluator {
private final View view;
public WidthEvaluator(View dashboard) {
this.view = dashboard;
}
@Override
public Integer evaluate(float fraction, Integer startValue, Integer endValue) {
ViewGroup.LayoutParams params = view.getLayoutParams();
params.width = super.evaluate(fraction, startValue, endValue);
view.setLayoutParams(params);
return params.width;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment