Android: interpolator attribute in XML definition of Android Animation

Source: Internet
Author: User
The following is an example of an over-animation effect switching between two activities:
(Note the overridependingtransition () method in it)
Java code
1. @ override
Public void oncreate (bundle savedinstancestate ){
2. Super. oncreate (savedinstancestate );
3.
4. setcontentview (R. layout. splashscreen );
5.
6. New handler (). postdelayed (New runnable (){
7. @ override
8. Public void run (){
9. Intent mainintent = new intent (splashscreen. This,
Androidnews. Class );
10. splashscreen. This. startactivity (mainintent );
11. splashscreen. This. Finish ();
12.
13. overridependingtransition (R. anim. mainfadein,
14. R. anim. splashfadeout );
15 .}
16.}, 3000 );
}

1. To implement the fade-in and fade-out effect, modify the overridependingtransition () method to overridependingtransition (Android. R. anim. fade_in, Android. R. anim
. Fade_out );

2. To slide left to right:
Overridependingtransition (Android. R. anim. slide_in_left, android.
R. anim. slide_out_right );

3. Implement zoomin and zoomout, which are similar to the entry and exit effects of the iPhone:
Overridependingtransition (R. anim. zoomin, R. anim. zoomout );
Here we define zoomin. xml and zoomout. xml.

Zoomin. XML code:

1. <? XML version = "1.0" encoding = "UTF-8"?>
2. <set
3. xmlns: Android = "http://schemas.android.com/apk/res/android"
4. Android: interpolator = "@ Android: anim/decelerate_interpolator">
<Scale Android: fromxscale = "2.0" Android: toxscale = "1.0"
5. Android: fromyscale = "2.0" Android: toyscale = "1.0"
6. Android: rjtx = "50% P" Android: 0000ty = "50% P"
7. Android: Duration = "@ Android: integer/config_mediumanimtime"/>
</Set>
Many people may not understand the meaning of Android: interpolator = "@ Android: anim/decelerate_interpolator", which is not clear in the document. In fact, it is very simple. refer to the following:
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:

The acceleratedecelerateinterpolator speed changes slowly at the beginning of the animation and the introduced place, accelerating
Accelerateinterpolator changes slowly at the beginning of the animation, and then starts acceleration.
Cycleinterpolator: specifies the number of times the animation is played cyclically, and the speed changes along the sine curve.
Decelerateinterpolator speed changes slowly at the beginning of the animation, and then starts to slow down
Linearinterpolator changes at an even rate in the 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.
Now, I hope to help you...

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.