Android Activity screen switching animation-slide switch between left and right

Source: Internet
Author: User

Android Activity screen switching animation-slide switch between left and right
If there is no X axis at the bottom of the mobile phone screen, and the Y axis on the left of the screen, when the Activity value is-100% p on the X axis, it is right on the left of the screen (Position 1 ), when the X axis value is 0% p, it is right in the screen (Position 2), and when X = 100% p, It is right on the right side of the screen (position 3 ). After knowing the position, we can achieve switching between the left and right slides. First, let the Activity to exit move from position 2 to position 1, and let the Activity to be exited move from position 3 to position 2, in this way, the switching from left to right can be achieved. The implementation process is as follows: first define two animations, create the anim directory in the res directory, and then create the xml file of the animation in the directory: out_to_left.xml (exit the animation from the left), in_from_right.xml (entering the animation from the right side) out_to_left.xml (moving from position 2 to position 1) <? Xml version = "1.0" encoding = "UTF-8"?> <Set xmlns: android = "http://schemas.android.com/apk/res/android" android: interpolator = "@ android: anim/accelerate_interpolator"> <translate android: fromXDelta = "0% p" android: toXDelta = "-100% p" android: duration = "500"/> </set> in_from_right.xml (from location 3 to location 2) <? Xml version = "1.0" encoding = "UTF-8"?> <Set xmlns: android = "http://schemas.android.com/apk/res/android" android: interpolator = "@ android: anim/accelerate_interpolator"> <translate android: fromXDelta = "100% p" android: toXDelta = "0% p" android: duration = "500"/> </set> android: fromXDelta animation start position, android: toXDelta animation end position, android: the duration of the duration animation. Copy the code public class LeftRightSlideActivity extends Activity {@ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main); Button button = (Button) findViewById (R. id. button1); button. setOnClickListener (new View. onClickListener () {@ Override public void onClick (View v) {Intent intent = new Intent (); intent. setClass (LeftRightSlideActivity. this, SlideSecondActivity. class); startActivity (intent); // you can set the animation to switch from the right, and exit overridePendingTransition (R. anim. in_from_right, R. anim. out_to_left );}});}}

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.