Splash.Java:
public class Splash extends Activity {
privateImageView iv_splash;
Intent intent;
@Override
protected void onCreate(BundlesavedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//隐藏标题栏与全屏显示
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.splash);
iv_splash=(ImageView)findViewById(R.id.iv_splash);
//初始化动画
AlphaAnimation animation=newAlphaAnimation(0.1f, 1.0f);
//设置动画运行的时间
animation.setDuration(3000);
//将动画加载到图片中
iv_splash.setAnimation(animation);
animation.setAnimationListener(newAnimationListener() {
/
@Override
public void onAnimationStart(Animationanimation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animationanimation) {
// TODO Auto-generated method stub
}
//动画结束时进行的操作
@Override
public void onAnimationEnd(Animation animation){
// TODO Auto-generated method stub
intent=new Intent(Splash.this,MainActivity.class);
startActivity(intent);
finish();
}
});
}
//可以通过触摸事件来结束动画
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
super.onTouchEvent(event);
intent=new Intent(Splash.this,MainActivity.class);
startActivity(intent);
finish();
return true;
}
2.布局文件:splash.xml
<?xml version="1.0"encoding="utf-8"?>
<LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/iv_splash"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/a6"
android:scaleType="fitXY"
/>
</LinearLayout>