count View Animation - Android User Interface

Android examples for User Interface:View Animation

Description

count View Animation

Demo Code


//package com.java2s;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.TextView;

public class Main {
    private static final Long TEXT_ANIMATION_DURATION = 1500L;

    public static void countViewAnimation(final TextView textView,
            boolean isDeleting, int count, Context context) {
        AlphaAnimation animation = new AlphaAnimation(1f, 0f);
        animation.setDuration(TEXT_ANIMATION_DURATION);
        textView.setText(String.valueOf(count));

        if (isDeleting) {
            textView.setTextColor(Color.GREEN);
        } else {/* w w  w  .  j a v  a2 s .  co  m*/
            textView.setTextColor(Color.RED);
        }
        animation.setAnimationListener(new Animation.AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {
                textView.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                textView.setVisibility(View.INVISIBLE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        textView.startAnimation(animation);
    }
}

Related Tutorials