Display various effects of Activity jump animations for Android

Source: Internet
Author: User

As we all know when using the native UI of Android, the Android Activity jump is a very hardware switching interface. In fact, you can set various animations for Android Activity jump. The following shows the effect:
 

The implementation is very simple. You can use overridePendingtransition (int inId, int outId. InId is the id of the xml file that enters the effect of the next interface, and outId is the xml file id of the exit effect of the current interface.

The effect is written in xml files. First, you need to create an anim folder under the res folder, and then put the xml file of the animation effect in it.
Below is the xml file to zoom in and exit:
Zoomin. xml:Copy codeThe Code is as follows: <? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android"
Android: interpolator = "@ android: anim/decelerate_interpolator">
<Scale android: fromXScale = "0.1" android: toXScale = "1.0"
Android: fromYScale = "0.1" android: toYScale = "1.0"
Android: Ready Tx = "50% p" android: Ready ty = "50% p"
Android: duration = "300"/>
<! -- Set the animation duration to 3 seconds to see the animation demo. -->
<Alpha
Android: fromalphi = "0.1"
Android: toAlpha = "1.0"
Android: duration = "300"/>
</Set>

Zoomout. xmlCopy codeThe Code is as follows: <? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android"
Android: interpolator = "@ android: anim/decelerate_interpolator"
Android: zAdjustment = "top">
<Scale android: fromXScale = "1.0" android: toXScale = ". 5"
Android: fromYScale = "1.0" android: toYScale = ". 5"
Android: Ready Tx = "50% p" android: Ready ty = "50% p"
Android: duration = "300"/>
<! -- Embedded animation duration
Android: duration = "@ android: integer/config_mediumAnimTime"
-->
<Alpha android: fromAlpha = "1.0" android: toAlpha = "0"
Android: duration = "300"/>
</Set>

MainActivity. java:Copy codeThe Code is as follows: public class MainActivity extends Activity implements OnClickListener {
Private Button btn1;
Private Button btn2;
Private Button btn3;
Private Button btn4;

@ Override
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. activity_1 );
Btn1 = (Button) findViewById (R. id. btn1 );
Btn2 = (Button) findViewById (R. id. btn2 );
Btn3 = (Button) findViewById (R. id. btn3 );
Btn4 = (Button) findViewById (R. id. btn4 );
Btn1.setOnClickListener (this );
Btn2.setOnClickListener (this );
Btn3.setOnClickListener (this );
Btn4.setOnClickListener (this );
}

@ Override
Public void onClick (View v ){
// TODO Auto-generated method stub
Int version = Integer. valueOf (android. OS. Build. VERSION. SDK );
Switch (v. getId ()){
Case R. id. btn1:
// Zoom in and out
StartActivity (new Intent (this, OtherActivity. class ));
If (version> 5 ){
OverridePendingTransition (R. anim. zoomin, R. anim. zoomout );
}
Break;
Case R. id. btn2:
// Fade-in and fade-out Jump
StartActivity (new Intent (this, OtherActivity. class ));
If (version> 5 ){
OverridePendingTransition (R. anim. alphain, R. anim. alphaout );
}
Break;
Case R. id. btn3:
// Jump left to right
StartActivity (new Intent (this, OtherActivity. class ));
If (version> 5 ){
OverridePendingTransition (R. anim. move_in_right, R. anim. move_out_right );
}
Break;
Case R. id. btn4:
// Jump right to left
StartActivity (new Intent (this, OtherActivity. class ));
If (version> 5 ){
OverridePendingTransition (R. anim. move_in_left, R. anim. move_out_left );
}
Break;
}
Finish ();
}
}

There are still a lot of animation effects. We need to use our imagination to design them ourselves ~

Related Article

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.