界面效果
1.修改自动生成的activity_welcom.xml文件,代码如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layoutWelcome"
android:layout_width="match_parent"
android:layout_height="match_parent"
<strong>android:background="@drawable/welcome_bg"</strong>
tools:context=".WelcomeActivity">
</RelativeLayout>
2.修改AndroidManifest.xml文件,修改闪屏界面为全屏模式:
<activity
android:name="cn.edu.bztc.walkersimulate.WelcomeActivity"
android:label="@string/title_activity_welcome"
<strong>android:theme="@android:style/Theme.NoTitleBar.Fullscreen"</strong> >
3.修改WelcomeActivity.java中的代码,实现停顿3秒后跳转
方式1:利用动画持续时间,动画结束后跳转,主要代码:
public class WelcomeActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
/*//1、利用动画持续时间,动画结束后跳转
RelativeLayout layoutWelcome=(RelativeLayout)findViewById(R.id.layoutWelcome);
AlphaAnimation alphaAnimation=new AlphaAnimation(0.1f,1.0f);
alphaAnimation.setDuration(3000);
layoutWelcome.startAnimation(alphaAnimation);
alphaAnimation.setAnimationListener(new AnimationListener(){
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
Intent intent=new Intent(WelcomeActivity.this,LoginActivity.class);
startActivity(intent);
}
@Override
public void onAnimationRepeat(Animation aimation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
}); }
方式2:使用Handler完成跳转:
/*//2、使用Handler完成跳转
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
Intent intent=new Intent(WelcomeActivity.this,LoginActivity.class);
startActivity(intent);
}
}, 3000);
方式3:使用多线程完成跳转:
//3、使用多线程完成跳转
new Thread(){
public void run(){
try{
Thread.sleep(3000);
Intent intent = new Intent(WelcomeActivity.this,GuideActivity.class);
startActivity(intent);
}catch(InterruptedException e){
e.printStackTrace();
}
};
}.start();
}