当前位置: 代码迷 >> 移动开发 >> 怎么在两个activity之间切换动画
  详细解决方案

怎么在两个activity之间切换动画

热度:8639   发布时间:2013-02-26 00:00:00.0
如何在两个activity之间切换动画?

原问题来自于CSDN问答频道,更多解决方案见:http://ask.csdn.net/questions/1354

我想实现当改变 activity 时,实现从左到右的滑动效果。我使用的下面的代码,但是没有获得所要的效果。请大家帮我看一下。

java 中的文件

super.onCreate(savedInstanceState);overridePendingTransition(R.anim.fadein, R.anim.fadeout);setContentView(R.layout.main);

在 res/anim目录下的两个文件
fadein.xml
<?xml version="1.0" encoding="utf-8"?><alpha xmlns:android="http://schemas.android.com/apk/res/android" android:duration="5000" android:fromAlpha="0.0" android:interpolator="@android:anim/slide_out_right" android:toAlpha="1.0" ></alpha>

fadeout.xml

<?xml version="1.0" encoding="utf-8"?><alpha xmlns:android="http://schemas.android.com/apk/res/android" android:duration="5000" android:fromAlpha="0.0" android:interpolator="@android:anim/slide_in_left" android:toAlpha="1.0" ></alpha>
解决方案:

protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.splashscreen);         new Handler().postDelayed(new Runnable() {             public void run() {                     /* Create an intent that will start the main activity. */                     Intent mainIntent = new Intent(SplashScreen.this,                             ConnectedActivity.class);                     mainIntent.putExtra("id", "1");                     //SplashScreen.this.startActivity(mainIntent);                     startActivity(mainIntent);                     /* Finish splash activity so user cant go back to it. */                     SplashScreen.this.finish();                     /* Apply our splash exit (fade out) and main                        entry (fade in) animation transitions. */                     overridePendingTransition(R.anim.mainfadein,R.anim.splashfadeout);             }     }, SPLASH_DISPLAY_TIME);       }


  相关解决方案