SoFunction
Updated on 2025-04-11

Android development animation implementation method

This article describes the animation implementation method of Android development. Share it for your reference. The specific analysis is as follows:

There are three types of animations:

Frame-by-frame animation, layout animation, and control animation

Control animation implementation

Custom animation effects are achieved by rewriting the applyTransformation (float interpolatedTime, Transformation t) function of Animation. In addition, initialize (int width, int height, int parentWidth, int parentHeight) function is generally implemented. This is a callback function tells the size parameters of the Animation target view. Here some related parameters can be initialized, such as setting the animation duration, setting the Interpolator, setting the reference point of the animation, etc.

OPhone will repeatedly call the applyTransformation function during the animation. Each time the parameter interpolated Time value is called, the parameter will change, and the parameter changes from 0 to 1. When the parameter is 1, it indicates that the animation ends. The transformed matrix is ​​obtained through the parameter Transformation, and various complex effects can be achieved by changing the matrix.

Here is an example of a control animation:

Animation anim = new Animation() { 
  @Override 
  protected void applyTransformation(float interpolatedTime, Transformation t) { 
 if (interpolatedTime == 1) { 
   (); 
 } 
 else { 
   ().height = initialHeight - (int)(initialHeight * interpolatedTime); 
   (); 
 } 
  } 
  @Override
  public boolean willChangeBounds() {
 return true;
  }
};

In the example, the height of a view gradually changes from the original height to 0. When the animation is over, the view disappears.

I hope this article will be helpful to everyone's Android programming design.