Created
May 10, 2012 19:45
-
-
Save tprochazka/2655404 to your computer and use it in GitHub Desktop.
How to animate width of any View
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ValueAnimator.ofObject(new WidthEvaluator(view), 50, 500).setDuration(400).start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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