Android realizes the method of adding animation effects to Activity interface switch

  • 2020-06-07 05:16:34
  • OfStack

This paper shows Android's method of adding animation effects to Activity interface switching in the form of an example, which has a good reference value for Android programmers. The specific methods are as follows:

Anyone familiar with Android programming should know that after Android 2.0 came overridePendingTransition(), with two parameters, one for the exit of the previous activity and one for the entry of activity.

Take a look at this sample code:


@Override  
public void onCreate(Bundle savedInstanceState) {  
   super.onCreate(savedInstanceState);  
   setContentView(R.layout.SplashScreen);  
   new Handler().postDelayed(new Runnable() {  
    @Override  
    public void run() {  
    Intent mainIntent = new Intent(SplashScreen.this,   AndroidNews.class);  
    SplashScreen.this.startActivity(mainIntent);  
    SplashScreen.this.finish();  
    overridePendingTransition(R.anim.mainfadein,  
     R.anim.splashfadeout);  
    }  
   }, 3000);  
}  

The code above is just part 1 of the splash screen.


getWindow().setWindowAnimations(int);  

It's not as good as the last one but it's ok.

To achieve the effect of fading in and out:


overridePendingTransition(Android.R.anim.fade_in,android.R.anim.fade_out);  

Effect of sliding from left to right:


overridePendingTransition(Android.R.anim.slide_in_left,android.R.anim.slide_out_right);  

To achieve the effect of zoomin and zoomout, i.e. the entry and exit effects similar to iphone:


overridePendingTransition(R.anim.zoomin, R.anim.zoomout);  

New ES33en. xml file:


<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:Android="http://schemas.android.com/apk/res/android" 
    Android:interpolator="@android:anim/decelerate_interpolator"> 
  <scale Android:fromXScale="2.0" android:toXScale="1.0" 
      Android:fromYScale="2.0" android:toYScale="1.0" 
      Android:pivotX="50%p" android:pivotY="50%p" 
      Android:duration="@android:integer/config_mediumAnimTime" /> 
</set> 

New zoomout. xml file:


<?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"> 
  <scale Android:fromXScale="1.0" android:toXScale=".5" 
      Android:fromYScale="1.0" android:toYScale=".5" 
      Android:pivotX="50%p" android:pivotY="50%p" 
      Android:duration="@android:integer/config_mediumAnimTime" /> 
  <alpha Android:fromAlpha="1.0" android:toAlpha="0" 
      Android:duration="@android:integer/config_mediumAnimTime"/> 
</set>  

It is believed that the examples described in this article will be valuable for your Android programming.


Related articles: