Android instance-Mobile security Defender (21)-Custom activity interface Toggle Animation

Source: Internet
Author: User

First, the goal.

Enables animation transitions between the two activity interfaces.

Second, the code implementation.

1. Create a new folder named Anim under the Res folder.

2. Create a new Android XML file (named Tran_out) in the new Anim folder, select the root element (in this case, translate) according to the animation requirements to animate the activity interface to move out of the screen.

3. In the new XML file, in the properties of the root tag <translate>, the namespace is automatically incremented when a property is entered. The Android:fromxdelta property represents the x-axis from which the origin is the upper-left corner of the screen, the length of the 100%p is exactly equal to the width of the screen (or parent component), and the minus sign can represent the other side. The Android:toxdelta property indicates which x axis to go to.

Move-out screen (tran_out.xml) file code:

1 <?xml version= "1.0" encoding= "Utf-8"?>2 <translate xmlns:android= "/http Schemas.android.com/apk/res/android "3     android:fromxdelta=" 100%p "4     android:toxdelta=" 0 "5     android:duration="6     android:fromydelta= "0"7     Android:toydelta = "0" >89 </translate>
View Code

4, the same production into the screen (Tran_in.xml) animation effect, the code is as follows:

1 <?xml version= "1.0" encoding= "Utf-8"?>2 <translate xmlns:android= "/http Schemas.android.com/apk/res/android "3     android:fromxdelta=" 100%p "4     android:toxdelta=" 0 "5     android:duration="6     android:fromydelta= "0"7     Android:toydelta = "0" >89 </translate>
View Code

5. In the Click event processing method that needs to place the animation, the overridependingtransition (int enteranim, int exitanim) method must be executed after the startactivity () or the finish () method, where the parameter int Enteranim is the ID that enters the animation file (tran_in.xml), the parameter int Exitanim is the ID of the move-out animation file (Tran_in.xml).

The Setup Wizard ui_1 click the event method (next) code, other similar:

1 //Next Click event2      Public voidNext (view view) {3Intent Intent =NewIntent (setupwizard_ui_1. This, Setupwizard_ui_2.class);4 startactivity (intent);5 finish ();6         //required to be executed behind finish () or startactivity (intent). 7 overridependingtransition (r.anim.tran_in, r.anim.tran_out);8}
View Code

  

Android instance-Mobile security Defender (21)-Custom activity interface Toggle Animation

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.