preface

  • The use of property animation isAndroidKnowledge commonly used in development
  • This article will present a comprehensive & detailed property animation learning guide, will introduce all the content of property animation in detail, including: significance, function, application scenes, work principle & specific use, hope you will like it.

directory


Schematic diagram


1. The significance of

  • Property animation (Property Animation) is theThe Android 3.0(API 11) after a new animation mode is provided
  • So why provide property animation (Property Animation)?

1.1 background

Implementing animations is very common in Android development, so the Android system provides two ways to implement animations from the beginning:

  • Frame by frame animation (Frame Animation)
  • Tween animation (Tweened animation

1.2 the problem

Frame-by-frame animation and tween animation have certain disadvantages:

A. Scope limitations: View

That is, tween animation can only work on the View, that is, you can only animate a Button, TextView, or even a LinearLayout, or other components inherited from the View, but you can’t animate non-View objects

  1. In some cases the animation is just a property of the view & object rather than the whole view;
  2. For example, if you want a view’s color to change dynamically, you need to animate the view’s color properties instead of animating the entire view
B. Do not change the properties of the View, just change the visual effect
  • The tween animation just changedViewWithout really changing itViewProperties.
  • For example, move the button in the upper-left corner of the screen to the lower-right corner of the screen through the tween animation
  • Clicking on the current position of the button (bottom right corner of the screen) has no effect, because the button is still in the top left corner of the screen. The tween animation just draws the button to the bottom right corner of the screen, changing the visual effect.
C. Single animation effect
  • Tween animation can only achieve translation, rotation, zoom and transparency of these simple animation requirements
  • Once you encounter relatively complex animation effects, that is, beyond the above four animation effects, then tween animation cannot be achieved.

That is, there are great limitations in functionality & scalability

1.3 Solution

  • In order to solve the defects of tween animation, inThe Android 3.0(API 11) To begin with, the system provides a new animation mode: property animation (Property Animation)
  • Next, I’ll cover property animation (Property Animation)

2. Introduction

  • Object: AnyJavaobject

No longer limited to View View objects

  • Animation effect: can customize various animation effects

No longer limited to the four basic transformations: translation, rotation, scale & transparency


Characteristics of 3.

  • Scope objects are extended: not just View objects, but even no objects
  • Animation effects: Not just the 4 basic transformations, but other animation effects
  • Field of action: introduced after API11

4. Working principle

  • In a certain time interval, the object is animated on the property by constantly changing the value and constantly assigning the value to the property of the object

It can be any property of any object

  • The specific working principle is as follows:


The working principle of

  • From how this works, you can see that property animation has two very important classes:ValueAnimatorClass &ObjectAnimator
  • In fact, the use of property animation basically depends on these two classes
  • So, I’ll focus on these two classes when I introduce the specific use of property animation below.

5. Specific use

The use of attribute animation is mainly as follows:

  1. Two usage method classes:ValueAnimatorClass &ObjectAnimator
  2. There are two helper classes: interpolator & estimator

More on this below

5.1 ValueAnimator class

  • Definition: a core class in the property animation mechanism
  • The principle of animation: through constant control value changes, and then constantly manually assigned to the attributes of the object, so as to achieve the animation effect. As shown in figure:


The working principle of

The ValueAnimator class has three important methods:

  1. Valueanimator. ofInt (int values)
  2. Valueanimator.offloat (float values)
  3. Valueanimator. ofObject (int values)
  • Android: The core use of this attribute animation class ValueAnimator learning guide please close!
  • I’ll move on to another important class:ObjectAnimatorclass

5.2 ObjectAnimator class

5.2.1 Principles of animation

Change the property value of the object directly, so as to achieve the animation effect

  1. Such as direct changeViewthealphaProperty to animate transparency
  2. Inherited fromValueAnimatorClass, the underlying animation implementation mechanism is based onValueAnimatorclass
  • Essential principle: by constantly controlling the change of value, and then constantly automatically assigned to the attributes of the object, so as to achieve the animation effect. The diagram below:


The working principle of


ObjectAnimator: ValueAnimator: ValueAnimator: ObjectAnimator: ValueAnimator

  • ValueAnimatorThe class changes the value first, and thenManual assignmentTo animate objects with properties; isindirectPerform operations on object properties;
  • ObjectAnimatorThe class changes the value first, and thenAutomatic assignmentTo animate objects with properties; isdirectlyPerform operations on object properties;

How to automatically assign attributes to objects is explained below

  • Android ObjectAnimator class learning Guide: Hand by hand with you to learn how to customize the property animation

5.3 Differences between ValueAnimator and ObjectAnimator

  • contrastValueAnimatorClass &ObjectAnimatorClass, both of which are property animations, are essentially the same: change the value and then assign it to the property of the object to animate it.
  • But the difference is this:

    ValueAnimatorThe class changes the value first, and thenManual assignmentTo animate objects with properties; isindirectPerform operations on object properties;

The ValueAnimator class is essentially a mechanism for changing values

The ObjectAnimator class changes the value and then automatically assigns it to the properties of the object to animate it; Is to operate directly on object properties;

ObjectAnimator is more intelligent and automated


5.4 interpolator


Schematic diagram

For more on TypeEvaluator, see Android: A Step-by-step guide to the mysterious TypeEvaluator


Valuation is 5.5


Schematic diagram

For a more detailed introduction, please read Android Animation: Interpolator will give you an insight into the mystery of interpolators.


5.6 Differences between interpolators and estimators

Estimators and interpolators are often confused. The differences are as follows:




Schematic diagram


6. Use tricks

Tips for using property animations include:

  • Combination of animation
  • Quick use of animation
  • Listening to the animation
  • Animation adapter

Android Animation: Do you know how to use these attributes

At this point, Android animation property animation in all the knowledge is explained.


7. To summarize

  • The essential principle of attribute animation: by constantly changing the value, and constantly assign the value to the property of the object, so as to achieve the animation effect of the object on the property; The specific working principle is as follows:


    The working principle of

  • Property animation is mainly used in the following classes, as follows:


Main usage classes


  • Next, I I will continue toAndroidanimationAnalysis, interested students can continue to pay attention to my operationWechat Public Account:
  • I would like to introduce to you a unique Android wechat public account (benefits return)
  • I’d like to invite you to write Android with me

Thumb up, please! Because your approval/encouragement is my biggest motivation to write!

  • aboutAndroidSeries of articles on animation
    1. This is a very detailed property animation summary & walkthrough Android animation: Hand-by-hand teach you to use tween animation Android frame by frame animation: about the use of frame by frame animation are here! Android Animation: Do you really know how to use interpolators and estimators? (including detailed example teaching)
    2. The principle of custom View, please refer to the article: (1) custom View basis – the most understandable custom View principle series (2) custom View Measure process – the most understandable custom View principle series (3) custom View Layout process – the most understandable custom View principle series (4) custom View Draw process – the most understandable custom View principle series
    3. Custom View application, please refer to the article: Why doesn’t your custom View wrap_content work? Why doesn’t wrap_content work?

Welcome to attentionCarson_HoJane books!

Share the dry things about Android development from time to time, the pursuit of short, flat, fast, but there is no lack of depth.