Toggle Animation for Android activity (overridependingtransition)

Source: Internet
Author: User

Overridependingtransition

1. The usual activity switch is to bounce from the middle and cover up the activity before. After seeing a lot of this effect, I want to change him to other effects, such as:

The acitvity to be displayed moves from the left to the right, and the covered activity is drawn from left to right.

In the Android development process, often encounter the transition between the effects of the problem, the following describes how to achieve the transition between left and right sliding, first understand the implementation of activity switching, starting from Android2.0 in the activity to add a method:

public void overridependingtransition (int enteranim, int exitanim)

which

Enteranim defines the animation when activity enters the screen (the animation to display when activity enters )

Exitanim defines the animation when activity exits the screen ( animated when the masked activity is drawn )

The Overridependingtransition method must be behind the startactivity () or the finish () method.

Android has several animations built in and can be seen on Android. R.anim class. In general, we need to define the effect of screen switching. First, we first understand the location definition of the activity, such as:

As can be seen in the phone screen under the x-axis, the left side of the screen is the y-axis, when the activity on the x-axis value of -100%p, just on the left side of the screen (position 1), when the x-axis value is 0%p, just before the screen (position 2), when x=100%p just right on the screen (position 3

In the use of overridependingtransition may encounter animation effect is not generated, the workaround is as follows:

1, Android system version 2.0 below, this no way, think of other ways to solve the switch animation bar.
2, in Activitygroup and other embedded activity, this is relatively easy to solve, with the following methods can be:
This.getparent (). Overridependingtransition can be solved.
3, in an activity of the inner class, or anonymous class, this time had to use handler to solve.

4, the display animation effect of the mobile phone is closed by man or other way. Now open to set-up display animation effect

2. Directly on the code

Animation to display when activity enters:

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Setxmlns:android= "Http://schemas.android.com/apk/res/android" >3     <Translate4         android:duration= "+"5 Android:fromxdelta= " -100%"6 Android:toxdelta= "0%p" />7 8 </Set>

Animations to be obscured when the activity slides out:

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Setxmlns:android= "Http://schemas.android.com/apk/res/android" >3     <Translate4         android:duration= "+"5 Android:fromxdelta= "0%"6 Android:toxdelta= "100%p" />7 8 </Set>

Mainactivity:

1  Public classMainactivityextendsActivity {2 3     PrivateButton btn;4 5 @Override6     protected voidonCreate (Bundle savedinstancestate) {7         Super. OnCreate (savedinstancestate);8 Setcontentview (r.layout.activity_main);9BTN =(Button) Findviewbyid (R.ID.BTN);TenBtn.setonclicklistener (NewOnclicklistener () { One  A @Override -              Public voidOnClick (View v) { -Intent i =NewIntent (); theI.setclass (mainactivity. This, Secondactivity.class); - startactivity (i); - overridependingtransition (R.anim.in_from_right, r.anim.out_left); -             } +         }); -     } +  A}

There is nothing substantive about the activity, it is not posted out.

The effect is as follows:

As follows:

Source Download

Toggle Animation for Android activity (overridependingtransition)

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.