Activity left slide out, right slide into animation toggle

Source: Internet
Author: User

Activity left slide, the right slide into the animation switch reprint please indicate the source: http://blog.csdn.net/u012301841/article/details/46920809

We all know that the animation between the default activity of Android system is: Slide left, slide right, press the back button to toggle the effect: Slide left, slide right. But now the handset manufacturers are customizing their own ROM, such as Mi UI and hammer OS and other phones, so that the android native switch animation has changed on different phones, and sometimes we need to let him back to the original state.

This is a picture that I stole on the internet, which clearly tells us how to change the motion of the Android animation:

The following is the specific implementation process:

Writing animation files

Create the Anim directory in the Res directory, and then create an animated XML file in the directory: Out_to_left.xml (exit animation from the left), In_from_right.xml (from the right into the animation)
Out_to_right.xml (exit animation from the right), In_from_left.xml (enter animation from the left)

In_from_left.xml

<?xml version="1.0" encoding="utf-8"?><translate xmlns:android="http://schemas.android.com/apk/res/android"    android:duration="500"    android:fromXDelta="-100%p"    android:interpolator="@android:anim/accelerate_interpolator"    android:toXDelta="0%p" ></translate>

In_from_right.xml

<?xml version="1.0" encoding="utf-8"?><translate xmlns:android="http://schemas.android.com/apk/res/android"    android:duration="500"    android:fromXDelta="100%p"    android:interpolator="@android:anim/accelerate_interpolator"    android:toXDelta="0%p" ></translate>

Out_to_left.xml

<?xml version="1.0" encoding="utf-8"?><translate xmlns:android="http://schemas.android.com/apk/res/android"    android:duration="500"    android:fromXDelta="0%p"    android:toXDelta="-100%p"    android:interpolator="@android:anim/accelerate_interpolator" ></translate>

Out_to_right.xml

<?xml version="1.0" encoding="utf-8"?><translate xmlns:android="http://schemas.android.com/apk/res/android"    android:duration="500"    android:fromXDelta="0%p"    android:toXDelta="100%p"    android:interpolator="@android:anim/accelerate_interpolator" ></translate>
Write a theme file

Open the Style.xml file in the values folder, insert a style node in it, and declare a topic.

    <style name="Anim_fade" parent="android:Theme.NoTitleBar">        <item name="android:windowAnimationStyle">@style/fade</item>    </style>

As you can see, the parent topic of the above topic is @android:style/theme.notitlebar, which is the majority of the attributes that inherit from the system theme.
One of the "Android:windowanimationstyle" properties is defined by us, located in the same style file as the values directory.

<stylename="Fade"Parent="@android: Style/animation.activity"> <Item name="Android:activityopenenteranimation"> @anim/in_from_right</Item> <Item name="Android:activityopenexitanimation"> @anim/out_to_left</Item> <Item name="Android:activitycloseenteranimation"> @anim/in_from_left</Item> <Item name="Android:activitycloseexitanimation"> @anim/out_to_right</Item> </style>

The following highlights the meaning of several of these properties, we can search online, I will directly understand what I said:
Now suppose there are two activity A and B, and B can be started in a. Also, the theme property of a and B are set to the properties defined above. So, the timing of the above animation is as follows:
(1) When a starts B, a exits, B enters, and a exits with the animated name Android:activityopenexitanimation, and the animated file is
When R.anim.out_to_left,b enters, the animation name is Android:activityopenenteranimation, and the animation file is r.anim.in_from_right.
(2) When B ends, b exits, a enters. b exit the animation name is android:activitycloseexitanimation, the animation file is R.anim.out_to_right, a entered when the animation name is Android: Activitycloseenteranimation, the animated file is R.anim.in_from_left.

The above all OK, we can see the desired effect. About the base friends online play lol, let him wait for 2 hours, estimates and so will be scolded dead, do not post, the code has been uploaded, need to download to see.

Code Download: http://download.csdn.net/detail/u012301841/8907457

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Activity left slide out, right slide into animation toggle

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.