Android plotting learning Summary (4) -- animation (medium)

Source: Internet
Author: User

In the android painting learning Summary (4) -- animation (I), I have introduced in detail the definition and use of tween animation. Due to limited space, many important aspects are not described, this article makes a complete summary on the one hand, and on the other hand, adds the missing questions in the previous article to help you better understand tween animation.

Summary of the Nature of tween animation: tween animation implements animation effects by performing a series of graphic transformations (including translation, scaling, rotation, and transparency change) on The View content. Specifically, a group of commands are pre-defined, which specify the type, trigger time, and duration of the graphic transformation. These commands can be defined in XML or source code. The program executes these commands along the timeline to achieve the animation effect.

Here, we need to analyze the two issues in depth:

  • How to control the animation running?
  • Animation running mode.
How to control the animation running?

This problem is also the tween animation mentioned in the previous article. It is estimated that we are confused about what interpolator is and what effect it has. Here we will provide a detailed description. According to the description of interpolator in the android SDK: interpolator defines the rate of change of an animation ). This allows the basic animation effects (alpha, scale, translate, and rotate) to accelerate, slow down, and repeat.

In a plain sense, the animation progress is controlled by interpolator. Interpolator defines the speed at which an animation changes, including constant speed, positive acceleration, negative acceleration, and irregular acceleration. Interpolator is a base class that encapsulates all the common methods of interpolator. It has only one method, that is, getinterpolation (float input ), this method maps a point on the timeline to a multiplier to be applied to the transformations of an animation. Android provides several interpolator subclasses to achieve different speed curves, as shown below:

Acceleratedecelerateinterpolator The speed changes are slow at the beginning of the animation and in the middle of the introduction.
Accelerateinterpolator Speed changes are slow at the beginning of the animation and acceleration starts.
Cycleinterpolator Specifies the number of times the animation is played cyclically, and the speed changes along the sine curve.
Decelerateinterpolator The speed changes slowly at the beginning of the animation, and then starts to slow down.
Linearinterpolator Changes at an even rate in an animation

For linearinterpolator, the change rate is a constant, that is, f (x) = x.
Public float getinterpolation (float input ){
Return input;
}
Several other sub-classes of interpolator are also implemented based on specific algorithms. You can also define your own interpolator subclass to achieve physical effects such as parabolic and free-falling.

Animation Running Mode

There are two animation modes:

  • Exclusive mode, that is, the main thread of the program enters a loop and refreshes the screen continuously according to the animation instructions until the animation ends;
  • Interrupt mode, that is, a separate thread counts the time, sends a notification to the main thread at a certain time, and the main thread updates the screen after receiving the notification;
Additional instructions: transformation class

Transformation records the matrix of the affine matrix. Each time an animation is triggered, an operation is performed on the original matrix, the bitmap of view can be multiplied by this matrix to achieve the corresponding operations (rotation, translation, scaling, etc ). The transformation class encapsulates the matrix and Alpha values. It has two important members: mmatrix and malpha. The transformation class diagram is as follows:

Summary

Graph transformation is implemented through an affine matrix. Graph transformation is the basic knowledge in graphics. Simply put, each transformation is a matrix operation. In Android, the canvas class contains the current matrix. When you call canvas. when drawbitmap (BMP, X, Y, paint) is drawn, a ndroid first performs a matrix operation on BMP and then displays the result on the canvas. In this way, programmers only need to constantly modify the canvas matrix and refresh the screen. The objects in the view will not stop performing graphic transformations, and the animation will be formed.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.