overridePendingTransition

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

  java

在startActivity後,調用overridePendingTransition方法,例如, 一)實現淡入淡出的效果以下: android

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

SplashActivity.this.finish(); iphone

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

二)由左向右滑入的效果改變一下參數便可 post

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

三)要實現zoomin和zoomout,即相似iphone的進入和退出時的效果 spa

在res目錄下新建文件夾anim,而後在anim下新建兩個xml,默認選項不用更改,分別命名爲zoomin.xml和zoomout.xml, code

<?xml version="1.0" encoding="utf-8"?> xml

<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>

相關文章
相關標籤/搜索