跪拜 Guibai
← Back to the summary

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

When developing a Splash screen or transition page, to enhance the visual experience, we often need to implement a series of coherent combined animations. This article records how to implement a custom SplashView that sequentially executes three animation effects: ball rotation, diffusion and aggregation, and water ripple reveal, and finally transitions to the actual page layout (represented here by a bottom image).

Insert image description

Effect:

shuibowen.gif


Core Member Variable Definitions

Before writing the drawing logic, let's first sort out the core properties and state variables that need to be maintained in SplashView:


Initialization and Drawing Framework Setup

In the custom View's initialization, the paint and color array are prepared, and after the view size is determined, key coordinates are calculated:

  1. Size Calculation (onSizeChanged): Get the control's center point centerX, centerY, and use the Pythagorean theorem to calculate half of the view's diagonal length, assign it to mDistance.
  2. State Dispatch (onDraw): Do not pile up complex if-else drawing logic in onDraw; instead, directly call the current state instance's drawState(canvas) method.

Phase One: Rotation Animation Implementation (RotateState)

The first phase makes six balls of different colors rotate around the center point. Create RotateState which inherits from SplashState and implement the following logic:

1. Ball Position Calculation and Drawing

2. Rotation Property Animation


Phase Two: Diffusion and Aggregation Animation Implementation (MergeState)

After the rotation ends, the six balls first spread outward, then aggregate toward the center, to prepare for the subsequent water ripple reveal. Create MergeState which inherits from SplashState:


Phase Three: Water Ripple Expansion Animation Implementation (ExpandState)

After aggregation, a hollow circle (water ripple) expands outward from the center point, gradually revealing the underlying real layout. Create ExpandState which inherits from SplashState:

1. Hollow Circle Drawing Logic

2. Water Ripple Property Animation


State Flow and Summary

The entire SplashView lifecycle achieves seamless transitions through alternating state objects:

  1. Initialize and enter Phase One (RotateState) by default, execute the rotation animation.
  2. After the rotation animation ends, instantiate Phase Two (MergeState) and trigger its drawing and diffusion-aggregation animation.
  3. After the diffusion-aggregation animation ends, instantiate Phase Three (ExpandState) and execute the water ripple expansion, finally fully revealing the underlying view.

Example code: Canvas-splash