ACtivity实现欢迎界面并添加动画切换效果
先看效果:
中间切换动画没来得及截图,凑合着看吧。
主要是java代码的实现:
Welcom.java
package kehr.activity.welcome; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.view.Window; import android.view.WindowManager; public class Welcome extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //全屏 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); //无标题 requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.welcome_layout); Handler handler = new Handler(); //使用pastDelayed方法延时 handler.postDelayed(new Runnable() { @Override public void run() { Intent intent = new Intent(Welcome.this, Start.class); startActivityForResult(intent, 11); //添加界面切换效果 int version = Integer.valueOf(android.os.Build.VERSION.SDK_INT); //只有android2.0(版本号为5)以上的版本支持 if(version >= 5) { //自定义动画效果 //overridePendingTransition(R.layout.zoom_enter, R.layout.zoom_exit); //系统动画效果 // overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out); overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right); } //结束欢迎界面 Welcome.this.finish(); } }, 3000); } }
Start.java
package kehr.activity.welcome; import android.app.Activity; import android.os.Bundle; public class Start extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.start_layout); //这里面就可以做其它的设置了,这里只是绑定了一个布局文件 } }
两个自定义动画文件:
zoom_enter.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>
zoom_exit.xml
<?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>
关于动画切换的效果参考: http://ipjmc.iteye.com/blog/1279056