Android Programming The Big Nerd Ranch Guide by Bill Phillips, Chris Stewart, Kristin Marsicano (z-lib.org)

(gtxtreme123) #1

Chapter 32  Property Animation


that tells ObjectAnimator what value is, say, a quarter of the way between a start value and end value.
Android provides a subclass of TypeEvaluator called ArgbEvaluator that will do the trick here.


Listing 32.13  Providing ArgbEvaluator (SunsetFragment.java)


private void startAnimation() {
float sunYStart = mSunView.getTop();
float sunYEnd = mSkyView.getHeight();


ObjectAnimator heightAnimator = ObjectAnimator
.ofFloat(mSunView, "y", sunYStart, sunYEnd)
.setDuration(3000);
heightAnimator.setInterpolator(new AccelerateInterpolator());


ObjectAnimator sunsetSkyAnimator = ObjectAnimator
.ofInt(mSkyView, "backgroundColor", mBlueSkyColor, mSunsetSkyColor)
.setDuration(3000);
sunsetSkyAnimator.setEvaluator(new ArgbEvaluator());


heightAnimator.start();
sunsetSkyAnimator.start();
}


Run your animation one more time, and you should see the sky fade to a beautiful orange color
(Figure 32.6).


Figure 32.6  Changing sunset color


Playing Animators Together


If all you need to do is kick off a few animations at the same time, then your job is simple: Call
start() on them all at the same time. They will all animate in sync with one another.

Free download pdf