JayVDiyk
JayVDiyk

Reputation: 4487

ValueAnimator Helper Class

I am a beginner in Android development.

Coming from iOS background I tend to use animations on Views

to animate a View in Android. I have found out to do it in a "normal" way

For example to animate alpha value of a view

valueAnimator = ValueAnimator.ofFloat(0, 100);

valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float value = (Float) animation.getAnimatedValue();
            viewToAnimate.alpha(value);
        }
    });

valueAnimator.setDuration(10000);
valueAnimator.start();

I am wondering if there is an easy way. Perhaps create a "Helper" class to animate an objects alpha value. Where we can pass in the View to animate and have it animated.

Something like AnimationHelper.animateAlpha(viewToAnimate, OF_VALUE, TO_VALUE, DURATION);

I am sorry to ask this question. Since my Java knowledge is rusty, I am wondering if there is any kind folks out there who is willing to help out.

Thank you

Upvotes: 0

Views: 174

Answers (1)

Vitaly Zinchenko
Vitaly Zinchenko

Reputation: 4911

Try this:

viewToAnimate.animate().alpha(TO_VALUE).setDuration(DURATION);

or this:

ObjectAnimator anim = ObjectAnimator.ofFloat(viewToAnimate, "alpha", FROM_VALUE, TO_VALUE);
anim.setDuration(DURATION);
anim.start();

Upvotes: 1

Related Questions