Set Activity Toggle animation under Android programming

Source: Internet
Author: User

Toggle animations for Activity settings

We know that we can set the subject of Activity through the android:theme property in the Androidmanifest.xml file. Many features about the appearance of Activity are defined in the topic. You can also define a toggle animation for your Activity in the theme. This is a way to apply Activity switching animations. Here's how to set up a toggle animation between Activity with a theme.

Define Activity topics that contain animations

Res/values/styles.xml, very simple, is to use Windowanimationstyle this property, specify the style to switch animation.

<name= "Animactivitytheme">    <Name  = "Android:windowanimationstyle">@style/feelyouwindowanimtheme</  Item></style>
Define Toggle Animation Style

Res/values/styles.xml

<stylename= "Feelyouwindowanimtheme"Parent= "@android: style/animation.activity">    <Itemname= "Android:activityopenenteranimation">@anim/in_from_left</Item>    <Itemname= "Android:activityopenexitanimation">@anim/out_from_right</Item>    <Itemname= "Android:activitycloseenteranimation">@anim/in_from_right</Item>    <Itemname= "Android:activitycloseexitanimation">@anim/out_from_left</Item></style>

Note that you need @android:style/Animation.Activity to inherit from. What do these 4 properties mean? Let's say we have 2 Activity, A1 and A2, respectively:

    • android:activityopenexitanimation
    • android:activityopenenteranimation
    • Span style= "Font-family:arial, Helvetica, Sans-serif; font-size:13px; " > when we exit from A2 back to A1, A2 disappears from the screen, this is called   Android:activitycloseexitanimation
    • when we get from A2 Exit back to A1, A1 appears on the screen, this is called   android:activitycloseenteranimation

Combined with the above-mentioned situation, I think it is easy to understand the name of the attribute in my mind.

Defining specific animation files

The animation here can be any kind of animation, such as transparency, displacement, scaling, and I'll give an example of displacement here. When we A1 start A2, I want A1 to pan out of the screen (out_from_right) from the right, and A2 to pan into the screen (In_from_left) from the left. when we exit from A2 back to A1, I want A2 to pan out of the screen (Out_from_left) from the left, A1 translate from the right into the screen (in_from_right)

Let me post a 4-specific animated XML file:

Anim/out_from_right.xml

<?XML version= "1.0" encoding= "Utf-8"?><!--Author:remex Huangwebsite:feelyou.info -<Translatexmlns:android= "Http://schemas.android.com/apk/res/android"android:duration= "$"Android:fromxdelta= "0"Android:fromydelta= "0"Android:toxdelta= "100%p"Android:toydelta= "0" ></Translate>

Anim/in_from_left.xml

<?XML version= "1.0" encoding= "Utf-8"?><!--Author:remex Huangwebsite:feelyou.info -<Translatexmlns:android= "Http://schemas.android.com/apk/res/android"android:duration= "$"Android:fromxdelta= " -100%p"Android:fromydelta= "0"Android:toxdelta= "0"Android:toydelta= "0" ></Translate>

Anim/out_from_left.xml

<?XML version= "1.0" encoding= "Utf-8"?><!--Author:remex Huangwebsite:feelyou.info -<Translatexmlns:android= "Http://schemas.android.com/apk/res/android"android:duration= "$"Android:fromxdelta= "0"Android:fromydelta= "0"Android:toxdelta= " -100%p"Android:toydelta= "0" ></Translate>

Anim/in_from_right.xml

<?XML version= "1.0" encoding= "Utf-8"?><!--Author:remex Huangwebsite:feelyou.info -<Translatexmlns:android= "Http://schemas.android.com/apk/res/android"android:duration= "$"Android:fromxdelta= "100%p"Android:fromydelta= "0"Android:toxdelta= "0"Android:toydelta= "0" ></Translate>
Apply to the corresponding Activity

Androidmenifest.xml

 <  activity  android:name  = "info.feelyou.demo.A1"   = "@style/animactivitytheme"  >  </ activity  >  <  activity  android:name  = "info.feelyou.demo.A2"   Android:theme  = "@style/animactivitytheme"  >  </ activity  >  

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.