每個Android應(yīng)用程序啟動之后都會出現(xiàn)一個Splash啟動界面,顯示產(chǎn)品LOGO、公司LOGO或者開發(fā)者信息。如果應(yīng)用程序啟動時間比較長,那么啟動界面就是一個很好的東西,可以讓用戶耐心等待這段枯燥的時間,提高用戶體驗。
1.splash.xml布局文件
1
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2
xmlns:tools="http://schemas.android.com/tools"
3
android:layout_width="match_parent"
4
android:layout_height="match_parent"
5
tools:context=".SplashActivity" >
6
7
<ImageView
8
android:layout_width="match_parent"
9
android:layout_height="match_parent"
10
android:background="@drawable/welcome_android"
11
android:scaleType="fitCenter" />
12
13
</RelativeLayout>

2

3

4

5

6

7

8

9

10

11

12

13

2.SplashActivity類,使用Handler的postDelayed方法,3秒后執(zhí)行跳轉(zhuǎn)到主視圖
1
package cn.eoe.leigo.splash;
2
3
import android.app.Activity;
4
import android.content.Intent;
5
import android.os.Bundle;
6
import android.os.Handler;
7
8
/**
9
*
10
* @{#} SplashActivity.java Create on 2013-5-2 下午9:10:01
11
*
12
* class desc: 啟動畫面
13
*
14
* <p>Copyright: Copyright(c) 2013 </p>
15
* @Version 1.0
16
* @Author <a href="mailto:gaolei_xj@163.com">Leo</a>
17
*
18
*
19
*/
20
public class SplashActivity extends Activity {
21
22
//延遲3秒
23
private static final long SPLASH_DELAY_MILLIS = 3000;
24
25
@Override
26
protected void onCreate(Bundle savedInstanceState) {
27
super.onCreate(savedInstanceState);
28
setContentView(R.layout.splash);
29
30
// 使用Handler的postDelayed方法,3秒后執(zhí)行跳轉(zhuǎn)到MainActivity
31
new Handler().postDelayed(new Runnable() {
32
public void run() {
33
goHome();
34
}
35
}, SPLASH_DELAY_MILLIS);
36
}
37
38
private void goHome() {
39
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
40
SplashActivity.this.startActivity(intent);
41
SplashActivity.this.finish();
42
}
43
}
44

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

3.配置AndroidManifest.xml





























