0
点赞
收藏
分享

微信扫一扫

android欢迎界面的编程实现[手相评分-软件实例]


首先,我们可以先看一下“手相评分”这款软件的启动画面。如下:



android欢迎界面的编程实现[手相评分-软件实例]_java

其实,做欢迎界面的原理非常简单,就是在onCreate函数中启动一个线程,线程体在睡眠几秒钟之后,跳转


到MainActivity即可。具体实现代码如下:


WelcomeActivity.java

[java]     view plain    copy    
    
  
1. import android.app.Activity;  
2. import android.content.Intent;  
3. import android.os.Bundle;  
4. import android.os.Handler;  
5. import android.os.Message;  
6. import android.view.Window;  
7. import android.view.WindowManager;  
8. /*
9.  *@author: ZhengHaibo  
10.  *web:   
12.  *2013-3-25  Nanjing,njupt,China
13.  */  
14. public class WelcomeActivity extends Activity {  
15. private static final int GOTO_MAIN_ACTIVITY = 0;  
16.   
17. @Override  
18. public void onCreate(Bundle savedInstanceState) {  
19. super.onCreate(savedInstanceState);  
20. // 设置无标题  
21.         requestWindowFeature(Window.FEATURE_NO_TITLE);  
22. // 设置全屏  
23.         getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  
24.                 WindowManager.LayoutParams.FLAG_FULLSCREEN);  
25.         setContentView(R.layout.activity_welcome);  
26. new MyTimer();  
27. //启动线程  
28.     }  
29.   
30. new Handler() {  
31. public void handleMessage(Message msg) {  
32.   
33. switch (msg.what) {  
34. case GOTO_MAIN_ACTIVITY:  
35. new Intent();  
36. this, SystemMain.class);  
37.                 startActivity(intent);  
38.                 finish();  
39. break;  
40. default:  
41. break;  
42.             }  
43.         };  
44.     };  
45.   
46. public class MyTimer extends Thread {  
47. public MyTimer() {  
48. // TODO Auto-generated constructor stub  
49.         }  
50. @Override  
51. public void run() {  
52. // TODO Auto-generated method stub  
53. try {  
54. 3000);// 线程暂停时间,单位毫秒  
55.                 mHandler.sendEmptyMessage(GOTO_MAIN_ACTIVITY);  
56. catch (InterruptedException e) {  
57. // TODO Auto-generated catch block  
58.                 e.printStackTrace();  
59.             }  
60.         }  
61.     }  
62. }



布局代码activity_welcome.xml


[html]     view plain    copy    
    
  
1. <?xml version="1.0" encoding="utf-8"?>  
2. <LinearLayout  
3. android:layout_width="fill_parent"  
4. android:layout_height="fill_parent"  
5. android:orientation="horizontal"  
6. android:background="@drawable/welcome"  
7. xmlns:android="http://schemas.android.com/apk/res/android">  
8. </LinearLayout>  
9.

举报

相关推荐

0 条评论