跪拜 Guibai
← All articles
Android

Chaining Rotate, Merge, and Ripple Reveal: A Custom Android SplashView

By _祝你今天愉快 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

The state-per-phase approach keeps onDraw clean and makes each phase independently testable, and the ripple reveal uses stroke-width math instead of clipping APIs, which simplifies drawing and keeps the animation GPU friendly.

Summary

A complete SplashView implementation splits its animation into three phases, each handled by its own state class (RotateState, MergeState, ExpandState). The first phase draws six colored balls at positions computed from a rotating angle and uses a ValueAnimator with a LinearInterpolator to spin them 720 degrees over about 2.4 seconds. When that finishes, MergeState animates the orbit radius from the ball size to a larger maxRadius using an OvershootInterpolator, then calls animator.reverse() to pull the balls back in, creating a springy gathering motion.

The final phase produces the reveal effect by drawing a growing hollow circle. Its stroke width shrinks from mDistance to zero as holeRadius increases from circleRadius to mDistance, which effectively masks out the background and reveals the underlying layout. All coordinates, like centerX and centerY, are computed in onSizeChanged; the diagonal half mDistance serves as the maximum spread distance. The example code is hosted on GitHub.

Takeaways
— The SplashView uses three state classes (RotateState, MergeState, ExpandState) that each implement drawState(canvas) so onDraw never grows a long if-else.
— Phase one uses ValueAnimator.ofFloat(0, 2π) with a LinearInterpolator, repeatCount(2), and 1200ms per rotation, for a total of around 2.4 seconds.
— Phase two animates mRotateRadius from circleRadius to maxRadius with OvershootInterpolator, then calls animator.reverse() to pull the balls back in.
— Phase three's hollow circle works by increasing holeRadius from circleRadius to mDistance while stroke = mDistance - holeRadius and realRadius = mDistance / 2 + holeRadius, so the center stays transparent and the edge expands.
— mDistance is computed as half the view's diagonal, giving the ripple a natural cover of the whole view port.
— Coordinates come from onSizeChanged (centerX, centerY) and are shared via member variables.
Conclusions

The state pattern here is a clean alternative to a single animator managing all phases; it isolates animation timing and draw logic per phase, making it easy to add new effects.

Using OvershootInterpolator on the radius gives the merge a springy bounce that builds anticipation for the reveal, a subtle but effective motion cue.

The ripple reveal is implemented purely with stroke width and radius math, avoiding Canvas.clipPath or BitmapShader, which keeps the drawing simple and GPU friendly.

Concepts & terms
OvershootInterpolator
An Android interpolator that overshoots the target value before settling back, creating a springy bounce effect.
State pattern
A design pattern where an object's behavior depends on its current state; here, each animation phase is a state class with its own draw and animation logic.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗