0

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

JayVDiyk
  • 4,277
  • 22
  • 70
  • 135

1 Answers1

1

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();
Vitaly Zinchenko
  • 4,871
  • 5
  • 36
  • 52
  • Thanks, btw is there any onComplete on liner method we can use on the `viewToAnimate.animate().alpha(TO_VALUE).setDuration(DURATION);` ? – JayVDiyk Dec 12 '15 at 09:13