在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>
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.os.Handler;
- import hgy.test.PendingTransition.R;
- public class MainActivity extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- new Handler().postDelayed(new Runnable(){
- @Override
- public void run() {
- Intent mainIntemt = new Intent(MainActivity.this,AndroidNews.class);
- MainActivity.this.startActivity(mainIntemt);
- MainActivity.this.finish();
- //overridePendingTransition(R.anim.fade_in,R.anim.fade_out);
- //实现淡入浅出的效果
- overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);
- //由左向右滑入的效果
- //overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right);
- //实现zoommin 和 zoomout,即类似iphone的进入和退出时的效果
- //overridePendingTransition(R.anim.zoomin, R.anim.zoomout);
- }
- },3000);
- }
- }