Leo Wiki Leo Wiki - 5 months ago 21
Android Question

How continuously zoom in - zoom out TextView text Android?

I'm trying to make TextView Zoom in - Zoom out continuously in my app for that, I tried the following code but it works only once and I want it for infinite time. My code is---

private void setTvZoomInOutAnimation(final TextView textView)
{
// TODO Auto-generated method stub

final float startSize = 20;
final float endSize = 13;
final int animationDuration = 900; // Animation duration in ms

ValueAnimator animator = ValueAnimator.ofFloat(startSize, endSize);
animator.setDuration(animationDuration);

animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
{
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator)
{
float animatedValue = (Float) valueAnimator.getAnimatedValue();
textView.setTextSize(animatedValue);
}
});

animator.start();
}


Please help.

Answer

Try following code, you have missed the following line--

//animator.setRepeatCount(ValueAnimator.INFINITE); // Use this line for infinite animationsanimator.setRepeatCount(2); // Use this for fix amount of time

private void setTvZoomInOutAnimation(final TextView textView) 
        {
            // TODO Auto-generated method stub

            final float startSize = 20;
            final float endSize = 13;
            final int animationDuration = 900; // Animation duration in ms

            ValueAnimator animator = ValueAnimator.ofFloat(startSize, endSize);
            animator.setDuration(animationDuration);

            animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() 
            {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) 
                {
                    float animatedValue = (Float) valueAnimator.getAnimatedValue();
                    textView.setTextSize(animatedValue);
                }
            });

            //animator.setRepeatCount(ValueAnimator.INFINITE);  // Use this line for infinite animations
            animator.setRepeatCount(2);
            animator.start();
        }

Hope it will help..

Comments