Explanation of jump animation on Android Activity interface

Instance 1 overridePendingTransition

Summary

Animation when two activities are switched. Use in overridePendingTransition
There are two parameters: the entry animation and the exit animation.

Note (call time)

1. Must be called immediately after StartActivity() or finish().
2. And it is valid in version 2.1 and above
 3. Mobile settings - display - animation, to be on

Achieve the effect of left in right out
MainActivity

startActivity(new Intent(OverridePendingTransitionActivity.this,SecondActivity.class));
overridePendingTransition(R.anim.leftin, R.anim.leftout);

SecondActivity

@Override
    public void onClick(View arg0) {
        finish();
        overridePendingTransition(R.anim.in, R.anim.out);   
    }

res/anim/leftin.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/decelerate_interpolator" >
  <translate 
       android:fromXDelta="100%p" 
        android:toXDelta="0%p"
        android:duration="400" />

 </set>

anim/leftout.xml

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

Because the theme is black by default, a short black screen will appear when executing the above jump animation, which is a very bad user experience. The solution is to add the following attribute to the theme file. Make the theme window transparent so that there is no black screen.
/string/styles.xml

<style name="AppTheme" parent="AppBaseTheme">
    <item name="android:windowIsTranslucent">true</item> 
</style>

summary
This example is suitable for animating a single interface
Example 2 (theme switching animation)

Define the effect of the toggle animation

<style name="Animation_Activity"          
      parent="@android:style/Animation.Activity">
  <item name="android:activityOpenEnterAnimation">@anim/right_in</item>
  <item name="android:activityOpenExitAnimation">@anim/left_out</item>
   <item name="android:activityCloseEnterAnimation">@anim/left_in</item>
  <item name="android:activityCloseExitAnimation">@anim/right_out</item>
</style>

Reference in topic

<style name="AppTheme" parent="AppBaseTheme">
 <item name="android:windowNoTitle">true</item>
 <itemname="android:windowAnimationStyle">@style/Animation_Activity
  </item>
</style>

Reference topic in Activity in Android manifest.xml file

<activity
            android:name=".MainActivity"
            android:theme="@style/AppTheme"
            android:label="@string/app_name" />

Detailed reference https://blog.csdn.net/github_25928675/article/details/49452183

Keywords: Android xml Mobile encoding

Added by jynmeyer on Sat, 04 Apr 2020 08:54:25 +0300