如何在Android中的两个活动之间应用幻灯片动画? [英] How to apply slide animation between two activities in Android?
本文介绍了如何在Android中的两个活动之间应用幻灯片动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我从一项活动转移到另一项活动时,我希望实现从左到右的滑动效果.为此,我正在使用以下代码,但未得到任何结果.请纠正我.
I want to achieve a sliding effect from left to right when I move from one activity to another. For that I am using the following code, but I am not getting any results. Please correct me.
在Java中,这两个文件:
In java both files:
super.onCreate(savedInstanceState);
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
setContentView(R.layout.main);
res/anim目录中的两个文件:
Two files in res/anim directory:
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);
}
这篇关于如何在Android中的两个活动之间应用幻灯片动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文