Android review-animation

Animation in Android is divided into three types: frame animation, view animation and attribute animation.

Frame animation

Frame animation is to play a group of pre-defined pictures in sequence, which is similar to watching a video, and pictures are played continuously one by one.

  • Define an XML file in the res/drawable directory, the root node is the animation-list provided by the system, and then put in a better-defined picture;
  • Use the AnimationDrawable class to play the picture in the Drawable defined in the first step to form an animation effect;

View animation

Also known as tweening animation, as the name suggests 它的作用对象只能是View, we only need to get a view, set its start and end positions, the middle view will be automatically filled in by the system, without the need for frame animation, every picture is Prepared in advance.

View animation changes the drawing effect of the View. The real position and related properties of the View will not change . This also causes the trigger area of ​​the click event to be the position before the animation instead of the position after the animation.

View animation types

There are four basic effects of translation (translate), zoom (scale), rotation (rotate), and transparency (alpha). On the basis of these four basic effects, we can select several of them to combine (use the set tag to combine these tags). To combine).

Two methods of use: definition in xml and dynamic setting in code. (The four effects correspond to the corresponding XXXAnimation class, such as translate corresponds to TranslateAnimation)

Special use scenarios for View animation

  • LayoutAnimation acts on the ViewGroup and assigns an animation to the ViewGroup, so that when its child elements come out, there will be this animation effect
  • The switching effect of Activity and Fragment

The entrance animation of the Activity must call the overridePendingTranstion method after the startActivity; the exit animation must call the overridePendingTranstion method after the finish method.

Property animation

Unlike View animation, it can animate any property of any object. It requires that the property of the object has set and get methods.

The difference between View animation and attribute animation

  • View animation changes the drawing effect of the View, and the real position and related properties of the View will not change.
  • The effect of property dynamics is actually to complete the change of an object from one property value to another within a time interval.

Interpolator and estimator

  • The main function of the interpolator is to give the change mode of the value in a given time (constant speed/acceleration, etc.)
  • The main function of the estimator is to determine the specific change value of the value.

Guess you like

Origin blog.csdn.net/why1092576787/article/details/114853281