Test Android Animation insert

Source: Internet
Author: User



Test Android Animation insert



Introduction to six types of inserts:


<i>android.view.animation.interpolator

Interpolator

[in ' t?:p? Uleit?] Follow the oral practice

N. The person who tampered with, the insertion procedure


<c>android.view.animation.accelerateinterpolator

Accelerate

English [k ' sel?re?t] beauty [k ' s?l?ret] global pronunciation and reading oral practice

Vt. Make...... To make a quick move; Growth

VI. accelerate; promote; increase;

Public float getinterpolation (float input) {

if (mfactor = = 1.0f) {//default: Mfactor = 1.0f;

return input * input; X^2

} else {

return (float) Math.pow (input, 2 * mfactor);

       }

   }

test: Slows down to 0 in the negative direction and then accelerates in the positive direction

Note: The test of the function formula can be used between the post: Customize the Android function curve control, get the rate change from the curve change trend


<c>android.view.animation.decelerateinterpolator

decelerate

British [di? ' Sel?re?t] Beauty [, Di ' s?l?ret] global pronunciation and reading oral practice

VI. Deceleration, reduce speed

Vt. To cause to decelerate

Public float getinterpolation (float input) {

float result;

if (mfactor = = 1.0f) {

result = (float) (1.0f-(1.0f-input) * (1.0f-input));

} else {

result = (float) (1.0f-math.pow ((1.0f-input), 2 * mfactor));

       }

return result;

   }

test: decrease by 1 before increase

<c>android.view.animation.acceleratedecelerateinterpolator

Public float getinterpolation (float input) {

return (float) (Math.Cos (input + 1) * Math.PI)/2.0f) + 0.5f;

   }

Test: 2 values for a period of change between 0 and 0.5 for the increase of the amplitude, then to 1 for the reduction increment, followed by a decrease in the increase, decreasing



<c>android.view.animation.cycleinterpolator

Public float getinterpolation (float input) {

return (float) (Math.sin (2 * mcycles * Math.PI * input));

   }

Test: The rate increases from 0 to about 0.5, then to about 0.7 for deceleration, then to 0.9 for negative acceleration, to 1 for negative acceleration to 0

<c>android.view.animation.linearinterpolator

Public float getinterpolation (float input) {

return input;

   }

Effect: The rate remains the same (the animation progress is consistent with the rate change)

<c>android.view.animation.overshootinterpolator

Overshoot Error

English [?? V? '? U?t] beauty [, ov? '?] UT] Follow the oral practice

Vt. To go beyond; Overdo it.

VI. Shoot the target, (the plane) slide out of the runway;

N. exceeding a goal;

tension Amount of overshoot. When tension equals 0.0f, there are no overshoot and the interpolator becomes a simple deceleration interpolator.

The amount of stretch exceeded. When stretched to 0 o'clock, this insert becomes a simple deceleration plug.

Public float getinterpolation (float t) {

//_o (t) = t * t * ((tension + 1) * t + tension)

//O (t) = _o (t-1) + 1

T-= 1.0f;

return T * t * ((mtension + 1) * t + mtension) + 1.0f;

   }

Test (mtension = 2.0f;): 0 to 0.5 reduction increments to about 1.2, then to 1 for deceleration to 1

Application testing:

(a mobile animation)

anim.setduration (300);

Anim.setinterpolator (New Interpolator () {

@Override

Public float getinterpolation (float input) {

System.out.println (input);

return input;

   }

});

06-26 14:38:03.087:i/system.out (27427): 0.0

06-26 14:38:03.087:i/system.out (27427): 0.0

06-26 14:38:03.097:i/system.out (27427): 0.036666665

06-26 14:38:03.117:i/system.out (27427): 0.093333334

06-26 14:38:03.127:i/system.out (27427): 0.15

06-26 14:38:03.147:i/system.out (27427): 0.20666666

06-26 14:38:03.167:i/system.out (27427): 0.26333332

06-26 14:38:03.177:i/system.out (27427): 0.32

06-26 14:38:03.197:i/system.out (27427): 0.37666667

06-26 14:38:03.217:i/system.out (27427): 0.43333334

06-26 14:38:03.227:i/system.out (27427): 0.49

06-26 14:38:03.247:i/system.out (27427): 0.5466667

06-26 14:38:03.267:i/system.out (27427): 0.60333335

06-26 14:38:03.287:i/system.out (27427): 0.6566667

06-26 14:38:03.297:i/system.out (27427): 0.7133333

06-26 14:38:03.317:i/system.out (27427): 0.77

06-26 14:38:03.337:i/system.out (27427): 0.83

06-26 14:38:03.347:i/system.out (27427): 0.8833333

06-26 14:38:03.367:i/system.out (27427): 0.94

06-26 14:38:03.387:i/system.out (27427): 1.0

06-26 14:38:03.397:i/system.out (27427): 1.0

different moving distances, 300 milliseconds duration, the insert is called always 21 times.

Modify the Getinterpolation implementation to "return input*input;" Effect: the animation achieves its position in a shorter period of time

Modify the Getinterpolation implementation to "return INPUT/2;", Effect: The animation does not reach the position within the specified time, the screen flashes to reach the position.


Summarize:


There are three main points:

1, Interpolator is a "rate of change", a basic animation of the "rate of change."

2, input is a 0.0f~1.0f floating-point type

3, suppose the distance is s, time is T, speed is V, all know s=v*t

Guessing how Interpolator works is:

First, the animation needs to split the during duration to get a continuous time slice

Then, the cycle time slice, through the position of each time slice in the entire duration of the ratio, that is, the progress of the animation process, and then use Interpolator to get a real-time rate

Finally, an offset is obtained by the instantaneous rate x time slice length, i.e. the position offset of the image before and after a frame.

is it possible that the animation time has not ended, but has reached the destination position? Or does the animation time end without reaching the destination?

and there's another problem: the duration doesn't coincide with the actual animation time, so how do you deal with it?

One strategy for guessing Android is to first complete the animation between time and then make subsequent adjustments.

Observing all the features of the above inserts, it is known that the path passed between the 0~1 is always more than the path of constant speed, that is to ensure that at the end of the animation can reach the specified position.

The best rate control is: At the same time, the custom rate changes and the path of constant velocity are the same. That is, like two people motorcycle, a person to maintain a constant speed, a person in accordance with the logic of the pace of change (or even the party walk), and finally all at the same time, the speed of the control logic is the best.

However, when designing a function formula, we should not only consider the time and area, but also consider the operational performance of the mobile side, but in fact it can not be both understandable.


Reference:

Http://blog.sina.com.cn/s/blog_4a6c59d60100wznv.html (Android Animation's interpolator insert)


Test Android Animation insert

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.