在startActivity后,调用overridePendingTransition方法,例如,
一)实现淡入淡出的效果如下:

 

startActivity(new Intent(SplashActivity.this, MainActivity.class));

SplashActivity.this.finish();

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

二)由左向右滑入的效果改变一下参数即可

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

三)要实现zoomin和zoomout,即类似iphone的进入和退出时的效果

在res目录下新建文件夹anim,然后在anim下新建两个xml,默认选项不用更改,分别命名为zoomin.xml和zoomout.xml,

 

<?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:duration="@android:integer/config_mediumAnimTime"

        android:fromXScale="2.0"

        android:fromYScale="2.0"

        android:pivotX="50%p"

        android:pivotY="50%p"

        android:toXScale="1.0"

        android:toYScale="1.0" />

</set>

 

<?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:duration="@android:integer/config_mediumAnimTime"

        android:fromXScale="1.0"

        android:fromYScale="1.0"

        android:pivotX="50%p"

        android:pivotY="50%p"

        android:toXScale=".5"

        android:toYScale=".5" />

    <alpha

        android:duration="@android:integer/config_mediumAnimTime"

        android:fromAlpha="1.0"

        android:toAlpha="0" />

</set>

 

  1. import android.app.Activity;  
  2. import android.content.Intent;  
  3. import android.os.Bundle;  
  4. import android.os.Handler;  
  5. import hgy.test.PendingTransition.R;  
  6.   
  7. public class MainActivity extends Activity {  
  8.     /** Called when the activity is first created. */  
  9.     @Override  
  10.     public void onCreate(Bundle savedInstanceState) {  
  11.         super.onCreate(savedInstanceState);  
  12.         setContentView(R.layout.main);  
  13.           
  14.         new Handler().postDelayed(new Runnable(){  
  15.   
  16.             @Override  
  17.             public void run() {  
  18.                 Intent mainIntemt = new Intent(MainActivity.this,AndroidNews.class);  
  19.                 MainActivity.this.startActivity(mainIntemt);  
  20.                 MainActivity.this.finish();  
  21.                 //overridePendingTransition(R.anim.fade_in,R.anim.fade_out);  
  22.                   
  23.                 //实现淡入浅出的效果  
  24.                 overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);  
  25.                  
  26.                 //由左向右滑入的效果  
  27.                 //overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right);  
  28.                   
  29.                 //实现zoommin 和 zoomout,即类似iphone的进入和退出时的效果  
  30.                 //overridePendingTransition(R.anim.zoomin, R.anim.zoomout);  
  31.             }  
  32.               
  33.         },3000);  
  34.     }  
  35. }  
posted on 2013-03-29 15:49  zhengbeibei  阅读(9193)  评论(0编辑  收藏  举报