public DroidAnimator ScaleTo(float[] scales, float[] scaleDurations, double?durationSeconds, double?delaySeconds, AnimationInterpolation?interpolation) { return(base.ExecuteFunction <DroidAnimator>("ScaleTo", delegate() { PropertyValuesHolder propX = PropertyValuesHolder.OfFloat("scaleX", scales); PropertyValuesHolder propY = PropertyValuesHolder.OfFloat("scaleY", scales); if (scaleDurations != null && (scaleDurations.Length > 0)) { int keyFrameCount = scaleDurations.Length; if (scales.Length < keyFrameCount) { keyFrameCount -= keyFrameCount - scales.Length; } Keyframe[] keyFrames = new Keyframe[keyFrameCount]; for (int i = 0; i < keyFrameCount; i++) { keyFrames[i] = Keyframe.OfFloat(scaleDurations[i], scales[i]); } propX.SetKeyframes(keyFrames); propY.SetKeyframes(keyFrames); } ObjectAnimator fadeAnimator = ObjectAnimator.OfPropertyValuesHolder(this.TargetView, propX, propY); SetDefaultsFor(fadeAnimator, durationSeconds, delaySeconds, interpolation); _animators.Add(fadeAnimator); return this; })); }
private void CreateAnimation() { if (animation == null) { ShapeHolder ball; ball = balls[0]; var yBouncer = ObjectAnimator.OfFloat(ball, "y", ball.Y, Height - BallSize); yBouncer.SetDuration(Duration); yBouncer.SetInterpolator(new CycleInterpolator(2)); yBouncer.Update += delegate { Invalidate(); }; ball = balls[1]; var pvhY = PropertyValuesHolder.OfFloat("y", ball.Y, Height - BallSize); var pvhAlpha = PropertyValuesHolder.OfFloat("alpha", 1.0f, 0f); var yAlphaBouncer = ObjectAnimator.OfPropertyValuesHolder(ball, pvhY, pvhAlpha); yAlphaBouncer.SetDuration(Duration / 2); yAlphaBouncer.SetInterpolator(new AccelerateInterpolator()); yAlphaBouncer.RepeatCount = 1; yAlphaBouncer.RepeatMode = ValueAnimatorRepeatMode.Reverse; ball = balls[2]; var pvhW = PropertyValuesHolder.OfFloat("width", ball.Width, ball.Width * 2); var pvhH = PropertyValuesHolder.OfFloat("height", ball.Height, ball.Height * 2); var pvTX = PropertyValuesHolder.OfFloat("x", ball.X, ball.X - BallSize / 2f); var pvTY = PropertyValuesHolder.OfFloat("y", ball.Y, ball.Y - BallSize / 2f); var whxyBouncer = ObjectAnimator.OfPropertyValuesHolder(ball, pvhW, pvhH, pvTX, pvTY); whxyBouncer.SetDuration(Duration / 2); whxyBouncer.RepeatCount = 1; whxyBouncer.RepeatMode = ValueAnimatorRepeatMode.Reverse; ball = balls[3]; pvhY = PropertyValuesHolder.OfFloat("y", ball.Y, Height - BallSize); var ballX = ball.X; var kf0 = Keyframe.OfFloat(0f, ballX); var kf1 = Keyframe.OfFloat(.5f, ballX + 100f); var kf2 = Keyframe.OfFloat(1f, ballX + 50f); var pvhX = PropertyValuesHolder.OfKeyframe("x", kf0, kf1, kf2); var yxBouncer = ObjectAnimator.OfPropertyValuesHolder(ball, pvhY, pvhX); yxBouncer.SetDuration(Duration / 2); yxBouncer.RepeatCount = 1; yxBouncer.RepeatMode = ValueAnimatorRepeatMode.Reverse; animation = new AnimatorSet(); animation.PlayTogether(yBouncer, yAlphaBouncer, whxyBouncer, yxBouncer); } }
public DroidAnimator TransitionBackgroundColor(int[] colors, float[] colorTransformDurations, double?durationSeconds, double?delaySeconds, AnimationInterpolation?interpolation) { return(base.ExecuteFunction <DroidAnimator>("BackgroundColorValue", delegate() { PropertyValuesHolder colorValues = PropertyValuesHolder.OfInt("backgroundColor", colors); if (colorTransformDurations == null || colorTransformDurations.Length == 0) { colorTransformDurations = new float[colors.Length]; for (int i = 0; i < colors.Length; i++) { colorTransformDurations[i] = i / colors.Length; } } if (colorTransformDurations != null && colorTransformDurations.Length > 0) { int keyFrameCount = colorTransformDurations.Length; if (colors.Length < keyFrameCount) { keyFrameCount -= (keyFrameCount - colors.Length); } Keyframe[] keyFrames = new Keyframe[keyFrameCount]; for (int i = 0; i < keyFrameCount; i++) { keyFrames[i] = Keyframe.OfFloat(colorTransformDurations[i], colors[i]); } colorValues.SetKeyframes(keyFrames); } ValueAnimator valueAnimator = ValueAnimator.OfPropertyValuesHolder(colorValues); valueAnimator.SetEvaluator(new ArgbEvaluator()); SetDefaultsFor(valueAnimator, durationSeconds, delaySeconds, interpolation); valueAnimator.Update += colorValueAnimator_Update; _animators.Add(valueAnimator); return this; })); }