Android development-animation implementation method

Source: Internet
Author: User

Android development-animation implementation method

This article describes how to implement animations for Android development. Share it with you 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

You can override the applyTransformation (float interpolatedTime, Transformation t) function of Animation to implement Custom Animation effects. In addition, initialize (int width, int height, int parentWidth, int parentHeight) is generally implemented) this is a callback function that tells Animation the size parameter of the target View. Here, you can initialize some related parameters, such as setting the Animation duration, setting the Interpolator, and setting the Animation reference point.

The OPhone calls the applyTransformation function repeatedly during the animation process. The value of interpolatedTime changes every time the parameter is called. The parameter changes from 0 to 1. When this parameter is set to 1, the animation ends. The Transformation parameter is used to obtain the transformed matrix. By changing the matrix, various complex effects can be achieved.

The following is an example of a control Animation:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

Animation anim = new Animation (){

@ Override

Protected void applyTransformation (float interpolatedTime, Transformation t ){

If (interpolatedTime = 1 ){

V. setVisibility (View. GONE );

}

Else {

V. getLayoutParams (). height = initialHeight-(int) (initialHeight * interpolatedTime );

V. requestLayout ();

}

}

@ Override

Public boolean willChangeBounds (){

Return true;

}

};

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

I hope this article will help you design your Android program.

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.