1.通过动画的渐变效果,将图片进行变化,设置一个漂亮的跳转!!!
Splash.java:
public class Splash extends Activity {
private ImageView iv_splash;Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
// 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=new AlphaAnimation(0.1f, 1.0f);
//设置动画运行的时间
animation.setDuration(3000);
//将动画加载到图片中
iv_splash.setAnimation(animation);animation.setAnimationListener(new AnimationListener() {
/
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// 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();
}
});
}
//可以通过触摸事件来结束动画
@Overridepublic 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>