Skip to content

Instantly share code, notes, and snippets.

@bmutinda
Forked from kanytu/textview_text_animation
Created November 19, 2015 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmutinda/700f985b40f3605e350d to your computer and use it in GitHub Desktop.
Save bmutinda/700f985b40f3605e350d to your computer and use it in GitHub Desktop.
public void animateTextView(int initialValue, int finalValue, final TextView textview) {
DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator(0.8f);
int start = Math.min(initialValue, finalValue);
int end = Math.max(initialValue, finalValue);
int difference = Math.abs(finalValue - initialValue);
Handler handler = new Handler();
for (int count = start; count <= end; count++) {
int time = Math.round(decelerateInterpolator.getInterpolation((((float) count) / difference)) * 100) * count;
final int finalCount = ((initialValue > finalValue) ? initialValue - count : count);
handler.postDelayed(new Runnable() {
@Override
public void run() {
textview.setText(finalCount + "");
}
}, time);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment