Android 启动界面的实现
1
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
package wht.android.loading; import android.content.Context; import android.graphics.Canvas; import android.util.AttributeSet; import android.widget.ImageView; public class LoadingView extends ImageView implements Runnable { private boolean isStop = false ; private int [] imageIds; private int index = 0 ; private int length = 1 ; public LoadingView(Context context) { this (context, null ); } public LoadingView(Context context, AttributeSet attrs) { super (context, attrs); } public void setImageIds( int [] imageId) { this .imageIds = imageId; if (imageIds != null && imageIds.length > 0 ) { length = imageIds.length; } } @Override protected void onDetachedFromWindow() { // TODO Auto-generated method stub super .onDetachedFromWindow(); isStop = true ; } @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super .onDraw(canvas); if (imageIds != null && imageIds.length > 0 ) { this .setImageResource(imageIds[index]); } } @Override public void run() { while (!isStop) { index = ++index % length; postInvalidate(); try { Thread.sleep( 400 ); } catch (InterruptedException e) { e.printStackTrace(); } } } public void startAnim() { new Thread( this ).start(); } } |
1
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
|
package wht.android.loading; import android.app.Activity; import android.os.Bundle; public class MainActivity extends Activity { private LoadingView main_imageview; @Override public void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.main); main_imageview = (LoadingView)findViewById(R.id.main_imageview); initLoadingImages(); new Thread() { @Override public void run() { main_imageview.startAnim(); } }.start(); } private void initLoadingImages() { int [] imageIds = new int [ 6 ]; imageIds[ 0 ] = R.drawable.loader_frame_1; imageIds[ 1 ] = R.drawable.loader_frame_2; imageIds[ 2 ] = R.drawable.loader_frame_3; imageIds[ 3 ] = R.drawable.loader_frame_4; imageIds[ 4 ] = R.drawable.loader_frame_5; imageIds[ 5 ] = R.drawable.loader_frame_6; main_imageview.setImageIds(imageIds); } } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
<? xml version = "1.0" encoding = "utf-8" ?> < LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android" android:orientation = "vertical" android:layout_width = "fill_parent" android:layout_height = "fill_parent" android:background = "#e1e1e1" > < wht.android.loading.LoadingView android:layout_gravity = "center_horizontal" android:layout_height = "wrap_content" android:id = "@+id/main_imageview" android:src = "@drawable/loader_frame_1" android:layout_marginTop = "190dp" android:layout_width = "wrap_content" ></ wht.android.loading.LoadingView > < TextView android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:text = "启动中..." android:layout_marginTop = "10dip" android:textColor = "#666666" android:layout_gravity = "center_horizontal" android:textSize = "20sp" /> </ LinearLayout > |
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。