Last active
November 19, 2015 11:34
-
-
Save kanytu/36f1c3f4c4f12908c689 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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