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 );}});}}